API url
API is now live on url: https://lopolis-api.now.sh/
You can verify the source code on url: https://lopolis-api.now.sh/_src/
Initial setup
Setting up a docker container
(for deployment in production)
To build the docker image run:
docker build -t lopolis-api_image .
To run the docker container run:
docker run -d --name lopolis-api_container lopolis-api_image
Setting up default flask server
(for debugging purposes, please don't use it in production)
Install requirements:
pip install -r app/requirements.txt
Run the server:
export FLASK_APP=app/main.py
python -m flask run
Functionalities
Requesting access token
To get access tokens for Lopolis, query endpoint /gettoken
with a POST request. Specify username and password in request payload, in JSON format
Example:
{"username": "<username>", "password": "<password>"}
The request should also contain the Content-Type
header:
{
"Content-Type": "application/json"
}
The server will respond with access token for Lopolis in JSON format
Example:
{
"error": false,
"status_code": 200,
"data": "<token>"
}
Getting menus
Send a POST request to endpoint /getmenus
with the JSON body format:
{
"month": "<month>",
"year": "<year>"
}
You must also include Authorization
header and set the Content-Type
header to application/json
Example:
{
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
The server will respond with a JSON object
Example:
{
"error": false,
"status_code": 200,
"data": {
"<date1>": {
"meal": "<meal-type>",
"menu-type": "<menu-type>",
"location": "<location>",
"readonly": false,
"menu_options": [
{
"value": "<menu-id>",
"text": "<menu-description>",
"selected": true
},
{
"value": "<menu-id>",
"text": "<menu-description>",
"selected": false
}
]
},
"<date2>": {
"meal": "<meal-type>",
"menu-type": "<menu-type>",
"location": "<location>",
"readonly": true,
"menu_options": [
{
"value": "<menu-id>",
"text": "<menu-description>",
"selected": true
}
]
}
}
}
Setting menus
Send a POST request to endpoint /setmenus
with the JSON body format:
{
"choices": {
"<date1>": "<menu-id>",
"<date2>": "<menu-id>"
}
}
The request must also contain the Authorization
header and Content-Type
header
Example:
{
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
If the request is successful, the server will respond with:
{
"error": false,
"status_code": 200
}
Getting checkouts
Warning! This feature is experimental
This functionality was introduced in version 1.0.1Send a POST request to endpoint /getmenus
with the JSON body format:
{
"month": "<month>",
"year": "<year>"
}
You must also include Authorization
header and set the Content-Type
header to application/json
Example:
{
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
The server will respond with a JSON object
Example:
{
"error": false,
"status_code": 200,
"data": {
"<date1>": "<meal-type>",
"<date2>": "<meal-type>",
"<date3>": "<meal-type>"
}
}
Please note: meal-type
field will always be either Malica
or Kosilo
Setting checkouts
Warning! This feature is experimental
This functionality was introduced in version 1.0.2Send a POST request to endpoint /setcheckouts
with the JSON body format:
{
"checkouts": {
"<date1>": "<meal-type>",
"<date2>": "<meal-type>"
}
}
The request must also contain the Authorization
header and Content-Type
header
Example:
{
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
Please note: meal-type
field must always be either Malica
or Kosilo
If the request is successful, the server will respond with:
{
"error": false,
"status_code": 200
}
Errors
If an error occurs during the processing of a request, the server will respond with:
{
"error": true,
"message": "*error message*",
"status_code": xxx
}
The status code will indicate the type of the error
List of most common error codes:
- 400 - bad request
- 401 - unauthorized (wrong password/invalid token)
- 405 - method not allowed (only endpoint
/about
accepts GET requests) - 429 - rate limiting
- 500 - application error
- 503 - nginx rate limiting
About
Query endpoint /about
. The server will respond with information about the info about API
Latest API info:
- Author: Rok Stular
- Author webpage: https://rstular.github.io/
- API version: 1.0.8
- API url: https://lopolis-api.now.sh/
- Documentation: https://rstular.github.io/projects/lopolis.html
- Source code: https://github.com/rstular/lopolis-api
- License: https://github.com/rstular/lopolis-api/blob/master/LICENSE (MIT)
- Changelog: https://github.com/rstular/lopolis-api/blob/master/CHANGELOG.md
- Bug reports: https://github.com/rstular/lopolis-api/issues
Easter egg
Since this is an easter egg, you should find it yourself!
Hint: coffee and tea