]> git.somenet.org - pub/jan/aic18.git/blob - service-reporting/README.md
second attempt for unifiying readmes
[pub/jan/aic18.git] / service-reporting / README.md
1 # PDF Service
2
3 ## API
4 Provides a REST-API to generate PDF reports for terms and their sentiment analysis results. The service uses an .NET Core wrapper for the wkhtmltopdf library to generate pdf out of html code.
5
6 `GET`: `/` Shows a demo page  
7 - param: none
8 - return: pdf file
9
10 `POST`: `/generatePDF/` Generates a pdf report for the given terms
11 - Header: `Content-Type`: `application/json`  
12 (optional) `Accept`: `application/base64` if the pdf should be in base64 instead of `application/pdf`  
13 - Body of request: Term[] e.g.
14 ```json
15 [
16   {
17     "name": "term 1",
18     "sentiment": 0.1
19   },
20   {
21     "name": "term 2",
22     "sentiment": 0.3
23   },
24   {
25     "name": "term 3",
26     "sentiment": 0.7
27   }
28 ]
29 ``` 
30 - return: pdf file
31
32 ## API errors
33 `TODO`
34
35 ### Term model
36 Term(string `Name`, double `Sentiment`)
37
38 ## run with docker
39 - `docker build -t service-reporting .`    
40 - `docker run -p YOUR_PORT:8083 service-reporting:latest`
41
42 ## run local
43 ### requirements
44 - .net core 2.2
45 - download [libwkhtml library](https://github.com/rdvojmoc/DinkToPdf/tree/master/v0.12.4) depending on your operating system and put it into `service-reporting` root folder
46 ### commands
47 - `dotnet run`
48
49 ## examples
50 - successfull pdf as application/json: `curl -X POST  http://localhost:8083/generatePDF  -H 'Content-Type: application/json'  -d '[ { "name": "A bad term", "sentiment": 0.1 }, { "name": "Another bad term", "sentiment": 0.3 }, { "name": "A neutral term", "sentiment": 0.5 }, { "name": "A good term", "sentiment": 0.65 }, { "name": "Another good term", "sentiment": 0.9 } ] ' -vs > test1.pdf`
51 - successfull pdf as application/base64: `curl -X POST http://localhost:8083/generatePDF -H 'Accept: application/base64' -H 'Content-Type: application/json' -d '[ { "name": "A bad term", "sentiment": 0.1 }, { "name": "Another bad term", "sentiment": 0.3 }, { "name": "A neutral term", "sentiment": 0.5 }, { "name": "A good term", "sentiment": 0.65 }, { "name": "Another good term", "sentiment": 0.9 } ] ' -vs | base64 -d > test2.pdf`
52 - invalid sentiment value: `curl -X POST http://localhost:8083/generatePDF -H 'Content-Type: application/json' -d '[ { "name": "Term with invalid sentiment value", "sentiment": 12 } ] ' -vs && echo`
53 - invalid json structure: `curl -X POST http://localhost:8083/generatePDF -H 'Content-Type: application/json' -d '[ { "name1": "A term with invalid json format", "sentiment": 0.5 } ] ' -vs && echo`