diff --git a/Installation/index.html b/Installation/index.html index 72225ee..835881d 100644 --- a/Installation/index.html +++ b/Installation/index.html @@ -690,7 +690,10 @@
Access the admin dashboard at your-domain:80
or your-domain:443
Info
I will not include steps for setting the domain name servers on this as you can follow the official documentation on your server or the Raspberry Pi documentation.
+Follow next step to check how you can and must made your first request.
diff --git a/assets/logo-docs.png b/assets/logo-docs.png index 1174227..1731076 100644 Binary files a/assets/logo-docs.png and b/assets/logo-docs.png differ diff --git a/search/search_index.json b/search/search_index.json index 0776cd4..d708cfb 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"ForkAPI","text":""},{"location":"#a-lightweight-restapi-client-that-manage-food-recipies-easily","title":"A lightweight RestAPI client that manage food recipies easily","text":"ForkAPI is a Django drf based project which can be easily integrated as a backend service for a mobile application or web application that can display, add, favorite a food recipies. The api is designed to be simple to use with build in Dashboard panel to add recipies manual or using the provided endpoints (views in Django).
You can benefit for future support of the project.
Get Started Installation
"},{"location":"Installation/","title":"Installation","text":"To install the API you need a Python 3.x installed also venv module and pip. Here will be covered two types of installation for debugging and for production.
"},{"location":"Installation/#mutual-steps","title":"Mutual Steps","text":"Clone the repository with the command
$ git clone https://github.com/mikebgrep/forkapi\n
Rename .env.example
to .env
In linux $ cd forkapi\n$ mv .env.example .env \n
Enter the environment variables in .env
file. PAGINATION_PAGE_SIZE
is used for pagination used in the API certain endpoint.DJANGO_SECRET
you can generate the secret online -> link or with the following command if you have installed django on the machine $ python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'\n
X_AUTH_HEADER
also you can generate random UUID online that will be used for authentication for the read only endpoint. Example header 261ec18d-0e81-4073-8d9e-b34a7a1e5e06
(Don`t use it this is for demo purpose)You can create a virtual environment and click of the API. Note replace the 3.x with actual Python version
$ python3.x -m venv .venv && source .venv/bin/activate\n$ pip install -r requirements.txt\n
Make the needed migrations so Django can create sqlite database file with tables.
$ cd forkapi\n$ python manage.py makemigrations authentication\n$ python manage.py makemigrations recipe\n$ python manage.py migrate\n
At this point everything should be ok, and you can start the server.
$ python manage.py runserver\n
You can access the dashboard admin panel on localhost:8000
. In this mode you can use it locally if in debug mode which you can change in /forkapi/settings.py
file line 27
"},{"location":"Installation/#installing-in-docker-container-production","title":"Installing in Docker container (Production)","text":"To installing in Docker container follow the steps bellow. For Raspberry Pi with Raspbian OS make sure to uncomment the packages in the main Dockerfile on line 16
fullchain.pem
and privkey.pem
files needed for the ssl settings in nginx
used as reverse proxy.nginx/ssl
folder.localhost
value for server_name
on lines 8
and 14
with your actual domain name in the forkapi/forkapi.nginx.conf
configuration file.That all you need to run the docker compose
command and the API will be deployed on the server instance or locally on your machine.
Depends of the available package\n\n$ docker compose up\n\nor \n\n$ docker-compose up\n
Access the admin dashboard at your-domain:80
or your-domain:443
I will not include steps for setting the domain name servers on this as you can follow the official documentation on your server or the Raspberry Pi documentation.
Follow next step to check how you can and must made your first request.
"},{"location":"contribution/","title":"Contribution","text":"Any contribution is welcomed and here the instructions to do so:
Info
For major futures you can open a issue first and then branch that should be named future/name-of-the-change
Note
If you decide to contribute and you have experience with Django a good starting point will be to rework the Django Admin Panel with more fancy look and feel.
"},{"location":"first-request/","title":"Make your first request","text":"After the API is deployed you need to create a superuser for the admin dashboard. This can be done ether with Django manage.py
python manage.py createsuperuser
command or using an API Client as Postman or curl CLI tool.
I will present the method with the curl as more convenient method but you can use and Postman.
"},{"location":"first-request/#creating-superuser","title":"Creating superuser","text":"To create a superuser for login into the Admin Dashboard use the following curl command in you terminal or powershell.
curl --location --request POST --header \"Content-type: application/json\" --header \"X-Auth-Header: X_AUTH_HEADER\" --data-raw '{\"username\":\"your-username\",\"password\":\"you-password\", \"is_superuser\": true}' 'https://your-domain-name/api/auth/signup'\n
Take a note that you need to change X_AUTH_HEADER
with the value from .env
fileyour-username
and your-password
with valid datahttps://your-domain-name
with actual domain name When you execute the curl command the admin user will be created you can log in to the admin dashboard from the base url of the api (the domain name).
"},{"location":"rest-references/","title":"Rest Reference","text":""},{"location":"rest-references/#restapi-reference","title":"RestAPI reference","text":""},{"location":"rest-references/#on-this-page-you-can-check-the-restapi-endpoints","title":"On this page you can check the RestAPI endpoints.","text":"Note
The API has build in csrf protection you may need to attach Cookie with value csrftoken=token to work proparly
"},{"location":"rest-references/#authentication","title":"Authentication","text":""},{"location":"rest-references/#create-admin-user","title":"Create admin user","text":"POST /api/auth/signup"},{"location":"rest-references/#payload","title":"Payload","text":"authentication.UserSerializer{\n \"username\": \"username\",\n \"password\": \"password\",\n \"is_superuser\": true\n}\n
"},{"location":"rest-references/#headers","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses","title":"Responses","text":"http code content-type response 201
application/json
User created successfully
400
application/json
{\"username\":[\"user with this username already exists.\"]}
"},{"location":"rest-references/#example-curl","title":"Example cURL","text":" curl --location 'host/api/auth/signup' --header 'X-Auth-Header: X_AUTH_HEADER' --header 'Content-Type: application/json' --data '{\"username\":\"username\",\"password\":\"password\",\"is_superuser\":true}'\n
"},{"location":"rest-references/#obtain-access-token","title":"Obtain access token","text":"POST /api/auth/token"},{"location":"rest-references/#payload_1","title":"Payload","text":"authentication.UserSerializer{\n \"username\": \"username\",\n \"password\": \"password\"\n}\n
"},{"location":"rest-references/#headers_1","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_1","title":"Responses","text":"http code content-type response 200
application/json
{\"token\":\"token\",\"user\":{\"username\":\"username\",\"is_superuser\":true}}
404
application/json
{\"detail\":\"No User matches the given query.\"}
403
application/json
{\"detail\": \"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_1","title":"Example cURL","text":" `curl --location 'host/api/auth/token' --header 'X-Auth-Header: X_AUTH_HEADER' --header 'Content-Type: application/json' --data '{\"username\":\"username\",\"password\":\"password\"}''\n
"},{"location":"rest-references/#recipe","title":"Recipe","text":""},{"location":"rest-references/#search-for-recipes","title":"Search for recipes","text":"GET /api/recipe/home/"},{"location":"rest-references/#parameters","title":"Parameters","text":"name type data type description name
query (optional)
string
Part or fulll name of the recipe.Recipe object
page
query (optional)
int
Page number if there a mutilple pages result
"},{"location":"rest-references/#headers_2","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_2","title":"Responses","text":"http code content-type response 200
application/json
{\"count\":int,\"next\":string,\"previous\":string,\"results\":[recipe.Recipe obj list]}
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_2","title":"Example cURL","text":" curl --location 'http://host:port/api/recipe/home/?name=name&page=1' --header 'X-Auth-Header: X_AUTH_HEADER\n
"},{"location":"rest-references/#get-favorite-recipes","title":"Get favorite recipes","text":"GET /api/recipe/home/favorites"},{"location":"rest-references/#headers_3","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_3","title":"Responses","text":"http code content-type response 200
application/json
{\"count\":int,\"next\":string,\"previous\":string,\"results\":[recipe.Recipe obj list]}
404
application/json
{\"detail\":\"No Recipe matches the given query.\"}
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_3","title":"Example cURL","text":" curl --location 'http://host:port/api/recipe/home/favorites/' --header 'X-Auth-Header: X_AUTH_HEADER\n
"},{"location":"rest-references/#get-trending-recipes","title":"Get trending recipes","text":"GET /api/recipe/trending"},{"location":"rest-references/#headers_4","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_4","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Recipe objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_4","title":"Example cURL","text":" curl --location 'localhost:8080/api/recipe/trending' --header 'X-Auth-Header: X_AUTH_HEADER\n
"},{"location":"rest-references/#update-favorite-status","title":"Update favorite status","text":"PATCH /api/recipe/int:pk/favorite"},{"location":"rest-references/#parameters_1","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to be favorited or unfavorited
"},{"location":"rest-references/#headers_5","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
"},{"location":"rest-references/#responses_5","title":"Responses","text":"http code content-type response 201
application/json
\"Success favorite recipe\"
201
application/json
\"Success unfavorite recipe\"
403
application/json
`{\"detail\":\"You must use authentication header\"} 404
application/json
Not Found
"},{"location":"rest-references/#example-curl_5","title":"Example cURL","text":" curl --location --request PATCH 'host/api/recipe/1/favorite' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#create-recipe","title":"Create recipe","text":"POST /api/recipe/"},{"location":"rest-references/#payload_2","title":"Payload","text":"recipe.Recipe object{\n \"image\": file,\n \"name\": string,\n \"serves\": int,\n \"video\": file (optional),\n \"category\": <int:pk>,\n \"tag\": <int:pk>,\n \"prep_time\": int,\n}\n
"},{"location":"rest-references/#headers_6","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
multipart/form-data
Recipe object
Recipe multipart/form-data object
"},{"location":"rest-references/#responses_6","title":"Responses","text":"http code content-type response 201
application/json
{recipe.Recipe object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_6","title":"Example cURL","text":" curl --location 'localhost:8080/api/recipe/' --header 'Authorization: Token d8916a5f6cf16d2c6a87bc7461bc4680245609f0' --form 'image=@\"/path/image.jpg\"' --form 'name=\"Test recipe creation\"' --form 'serves=\"5\"' --form 'category=\"1\"' --form 'tag=1' --form 'prep_time=\"45\"'\n
"},{"location":"rest-references/#update-recipe-main-info-without-ingredients-and-steps","title":"Update recipe main info (without ingredients and steps)","text":"PUT /api/recipe/int:pk"},{"location":"rest-references/#payload_3","title":"Payload","text":"recipe.Recipe object{\n \"image\": file,\n \"name\": string,\n \"serves\": int,\n \"video\": file (optional),\n \"category\": <int:pk>,\n \"tag\": <int:pk>,\n \"prep_time\": int,\n}\n
"},{"location":"rest-references/#parameters_2","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to be updated
"},{"location":"rest-references/#headers_7","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
multipart/form-data
Recipe object
Recipe multipart/form-data object
"},{"location":"rest-references/#responses_7","title":"Responses","text":"http code content-type response 200
application/json
{recipe.Recipe object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_7","title":"Example cURL","text":" curl --location --request PUT 'host/api/recipe/1' --header 'Authorization: Token d8916a5f6cf16d2c6a87bc7461bc4680245609f0' --form 'image=@\"/path/image.jpg\"' --form 'name=\"Update name\"' --form 'serves=\"4\"' --form 'category=\"1\"' --form 'tag=\"1\"' --form 'prep_time=\"21\"'\n
"},{"location":"rest-references/#category","title":"Category","text":""},{"location":"rest-references/#get-all-categories","title":"Get all categories","text":"GET /api/recipe/trending"},{"location":"rest-references/#headers_8","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_8","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Category objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_8","title":"Example cURL","text":" curl --location 'host/api/recipe/category' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#get-all-categories-recipes","title":"Get all categories recipes","text":"GET /api/recipe/category/int:pk/recipes"},{"location":"rest-references/#parameters_3","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Category primary key
"},{"location":"rest-references/#headers_9","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_9","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Recipe objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_9","title":"Example cURL","text":" curl --location 'host/api/recipe/category/1/recipes' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#create-category","title":"Create category","text":"POST /api/recipe/category/add"},{"location":"rest-references/#payload_4","title":"Payload","text":"recipe.Category object{\n \"name\": string\n}\n
"},{"location":"rest-references/#headers_10","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_10","title":"Responses","text":"http code content-type response 201
application/json
{recipe.Category object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_10","title":"Example cURL","text":" curl --location 'host/api/recipe/category/add' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '{\"name\":\"Greek\"}'\n
"},{"location":"rest-references/#update-category","title":"Update category","text":"PUT /api/recipe/category/int:pk"},{"location":"rest-references/#payload_5","title":"Payload","text":"recipe.Category object{\n \"name\": string,\n\n}\n
"},{"location":"rest-references/#parameters_4","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Category primary key
"},{"location":"rest-references/#headers_11","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_11","title":"Responses","text":"http code content-type response 200
application/json
{recipe.Recipe object}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
404
application/json
{\"detail\":\"No Category matches the given query.\"}
"},{"location":"rest-references/#example-curl_11","title":"Example cURL","text":" curl --location --request PUT 'host/api/recipe/category/6' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --header 'Content-Type: application/json' --data '{\"name\":\"Italiano\"}'\n
"},{"location":"rest-references/#tag","title":"Tag","text":""},{"location":"rest-references/#get-all-tags","title":"Get all tags","text":"GET /api/recipe/tags"},{"location":"rest-references/#headers_12","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_12","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Tag objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_12","title":"Example cURL","text":" curl --location 'host/api/recipe/tags' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#get-all-recipes-from-tag","title":"Get all recipes from tag","text":"GET /api/recipe/tag/int:pk/recipes"},{"location":"rest-references/#parameters_5","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Tag primary key
"},{"location":"rest-references/#headers_13","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_13","title":"Responses","text":"http code content-type response 200
application/json
{\"count\":int,\"next\":string,\"previous\":string,\"results\":[recipe.Recipe obj list]}
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_13","title":"Example cURL","text":" curl --location 'host/api/recipe/tag/<int:pk>/recipes' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#create-tag","title":"Create tag","text":"POST /api/recipe/tag/add"},{"location":"rest-references/#payload_6","title":"Payload","text":"recipe.Tag object{\n \"name\": string\n}\n
"},{"location":"rest-references/#headers_14","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_14","title":"Responses","text":"http code content-type response 201
application/json
{recipe.Category object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_14","title":"Example cURL","text":" curl --location 'host/api/recipe/tag/add' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '{\"name\":\"Summer vibes\"}'\n
"},{"location":"rest-references/#update-tag","title":"Update tag","text":"PUT /api/recipe/tag/int:pk"},{"location":"rest-references/#payload_7","title":"Payload","text":"recipe.Category object{\n \"name\": string,\n\n}\n
"},{"location":"rest-references/#parameters_6","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Tag primary key
"},{"location":"rest-references/#headers_15","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_15","title":"Responses","text":"http code content-type response 200
application/json
{recipe.Tag object}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
404
application/json
{\"detail\":\"No Category matches the given query.\"}
"},{"location":"rest-references/#example-curl_15","title":"Example cURL","text":" curl --location --request PUT 'host/api/recipe/tag/1' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --header 'Content-Type: application/json' --data '{\"name\":\"Summer Vibes\"}'\n
"},{"location":"rest-references/#ingredients","title":"Ingredients","text":"POST /api/recipe/int:pk/ingredients"},{"location":"rest-references/#payload_8","title":"Payload","text":"recipe.Igredient object list[\n {\n \"name\": \"string,\n \"quantity\": string,\n \"metric\": \"string\n },\n {\n \"name\": \"string,\n \"quantity\": string,\n \"metric\": \"string\n },\n....\n]\n
"},{"location":"rest-references/#parameters_7","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to which to link the ingredients
"},{"location":"rest-references/#headers_16","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_16","title":"Responses","text":"http code content-type response 201
application/json
[{recipe.Ingrediant object}]
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_16","title":"Example cURL","text":" curl --location 'host/api/recipe/ingredients' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '[{\"name\":\"Kasher salt\",\"quantity\":\"1/5\",\"metric\":\"tbsp\",\"recipe\":24}]'\n
"},{"location":"rest-references/#steps","title":"Steps","text":"POST /api/recipe/int:pk/steps"},{"location":"rest-references/#payload_9","title":"Payload","text":"recipe.Step object list[\n {\n \"text\": string\n },\n {\n \"text\": string\n },\n....\n]\n
"},{"location":"rest-references/#parameters_8","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to which to link the steps
"},{"location":"rest-references/#headers_17","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_17","title":"Responses","text":"http code content-type response 201
application/json
[{recipe.Step object}]
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_17","title":"Example cURL","text":" curl --location 'host/api/recipe/ingredients' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '[{\"text\":\"Heat the oven\",\"recipe\":1}]'\n
"},{"location":"user-guide/","title":"User Guide","text":"The documentation for ForkAPI contains number of sections that are listed bellow.
ForkAPI is a Django drf based project which can be easily integrated as a backend service for a mobile application or web application that can display, add, favorite a food recipies. The api is designed to be simple to use with build in Dashboard panel to add recipies manual or using the provided endpoints (views in Django).
You can benefit for future support of the project.
Get Started Installation
"},{"location":"Installation/","title":"Installation","text":"To install the API you need a Python 3.x installed also venv module and pip. Here will be covered two types of installation for debugging and for production.
"},{"location":"Installation/#mutual-steps","title":"Mutual Steps","text":"Clone the repository with the command
$ git clone https://github.com/mikebgrep/forkapi\n
Rename .env.example
to .env
In linux $ cd forkapi\n$ mv .env.example .env \n
Enter the environment variables in .env
file. PAGINATION_PAGE_SIZE
is used for pagination used in the API certain endpoint.DJANGO_SECRET
you can generate the secret online -> link or with the following command if you have installed django on the machine $ python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'\n
X_AUTH_HEADER
also you can generate random UUID online that will be used for authentication for the read only endpoint. Example header 261ec18d-0e81-4073-8d9e-b34a7a1e5e06
(Don`t use it this is for demo purpose)You can create a virtual environment and click of the API. Note replace the 3.x with actual Python version
$ python3.x -m venv .venv && source .venv/bin/activate\n$ pip install -r requirements.txt\n
Make the needed migrations so Django can create sqlite database file with tables.
$ cd forkapi\n$ python manage.py makemigrations authentication\n$ python manage.py makemigrations recipe\n$ python manage.py migrate\n
At this point everything should be ok, and you can start the server.
$ python manage.py runserver\n
You can access the dashboard admin panel on localhost:8000
. In this mode you can use it locally if in debug mode which you can change in /forkapi/settings.py
file line 27
"},{"location":"Installation/#installing-in-docker-container-production","title":"Installing in Docker container (Production)","text":"To installing in Docker container follow the steps bellow. For Raspberry Pi with Raspbian OS make sure to uncomment the packages in the main Dockerfile on line 16
fullchain.pem
and privkey.pem
files needed for the ssl settings in nginx
used as reverse proxy.nginx/ssl
folder.localhost
value for server_name
on lines 8
and 14
with your actual domain name in the forkapi/forkapi.nginx.conf
configuration file.That all you need to run the docker compose
command and the API will be deployed on the server instance or locally on your machine.
Depends of the available package\n\n$ docker compose up\n\nor \n\n$ docker-compose up\n
Access the admin dashboard at your-domain:80
or your-domain:443
Info
I will not include steps for setting the domain name servers on this as you can follow the official documentation on your server or the Raspberry Pi documentation.
Follow next step to check how you can and must made your first request.
"},{"location":"contribution/","title":"Contribution","text":"Any contribution is welcomed and here the instructions to do so:
Info
For major futures you can open a issue first and then branch that should be named future/name-of-the-change
Note
If you decide to contribute and you have experience with Django a good starting point will be to rework the Django Admin Panel with more fancy look and feel.
"},{"location":"first-request/","title":"Make your first request","text":"After the API is deployed you need to create a superuser for the admin dashboard. This can be done ether with Django manage.py
python manage.py createsuperuser
command or using an API Client as Postman or curl CLI tool.
I will present the method with the curl as more convenient method but you can use and Postman.
"},{"location":"first-request/#creating-superuser","title":"Creating superuser","text":"To create a superuser for login into the Admin Dashboard use the following curl command in you terminal or powershell.
curl --location --request POST --header \"Content-type: application/json\" --header \"X-Auth-Header: X_AUTH_HEADER\" --data-raw '{\"username\":\"your-username\",\"password\":\"you-password\", \"is_superuser\": true}' 'https://your-domain-name/api/auth/signup'\n
Take a note that you need to change X_AUTH_HEADER
with the value from .env
fileyour-username
and your-password
with valid datahttps://your-domain-name
with actual domain name When you execute the curl command the admin user will be created you can log in to the admin dashboard from the base url of the api (the domain name).
"},{"location":"rest-references/","title":"Rest Reference","text":""},{"location":"rest-references/#restapi-reference","title":"RestAPI reference","text":""},{"location":"rest-references/#on-this-page-you-can-check-the-restapi-endpoints","title":"On this page you can check the RestAPI endpoints.","text":"Note
The API has build in csrf protection you may need to attach Cookie with value csrftoken=token to work proparly
"},{"location":"rest-references/#authentication","title":"Authentication","text":""},{"location":"rest-references/#create-admin-user","title":"Create admin user","text":"POST /api/auth/signup"},{"location":"rest-references/#payload","title":"Payload","text":"authentication.UserSerializer{\n \"username\": \"username\",\n \"password\": \"password\",\n \"is_superuser\": true\n}\n
"},{"location":"rest-references/#headers","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses","title":"Responses","text":"http code content-type response 201
application/json
User created successfully
400
application/json
{\"username\":[\"user with this username already exists.\"]}
"},{"location":"rest-references/#example-curl","title":"Example cURL","text":" curl --location 'host/api/auth/signup' --header 'X-Auth-Header: X_AUTH_HEADER' --header 'Content-Type: application/json' --data '{\"username\":\"username\",\"password\":\"password\",\"is_superuser\":true}'\n
"},{"location":"rest-references/#obtain-access-token","title":"Obtain access token","text":"POST /api/auth/token"},{"location":"rest-references/#payload_1","title":"Payload","text":"authentication.UserSerializer{\n \"username\": \"username\",\n \"password\": \"password\"\n}\n
"},{"location":"rest-references/#headers_1","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_1","title":"Responses","text":"http code content-type response 200
application/json
{\"token\":\"token\",\"user\":{\"username\":\"username\",\"is_superuser\":true}}
404
application/json
{\"detail\":\"No User matches the given query.\"}
403
application/json
{\"detail\": \"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_1","title":"Example cURL","text":" `curl --location 'host/api/auth/token' --header 'X-Auth-Header: X_AUTH_HEADER' --header 'Content-Type: application/json' --data '{\"username\":\"username\",\"password\":\"password\"}''\n
"},{"location":"rest-references/#recipe","title":"Recipe","text":""},{"location":"rest-references/#search-for-recipes","title":"Search for recipes","text":"GET /api/recipe/home/"},{"location":"rest-references/#parameters","title":"Parameters","text":"name type data type description name
query (optional)
string
Part or fulll name of the recipe.Recipe object
page
query (optional)
int
Page number if there a mutilple pages result
"},{"location":"rest-references/#headers_2","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_2","title":"Responses","text":"http code content-type response 200
application/json
{\"count\":int,\"next\":string,\"previous\":string,\"results\":[recipe.Recipe obj list]}
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_2","title":"Example cURL","text":" curl --location 'http://host:port/api/recipe/home/?name=name&page=1' --header 'X-Auth-Header: X_AUTH_HEADER\n
"},{"location":"rest-references/#get-favorite-recipes","title":"Get favorite recipes","text":"GET /api/recipe/home/favorites"},{"location":"rest-references/#headers_3","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_3","title":"Responses","text":"http code content-type response 200
application/json
{\"count\":int,\"next\":string,\"previous\":string,\"results\":[recipe.Recipe obj list]}
404
application/json
{\"detail\":\"No Recipe matches the given query.\"}
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_3","title":"Example cURL","text":" curl --location 'http://host:port/api/recipe/home/favorites/' --header 'X-Auth-Header: X_AUTH_HEADER\n
"},{"location":"rest-references/#get-trending-recipes","title":"Get trending recipes","text":"GET /api/recipe/trending"},{"location":"rest-references/#headers_4","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_4","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Recipe objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_4","title":"Example cURL","text":" curl --location 'localhost:8080/api/recipe/trending' --header 'X-Auth-Header: X_AUTH_HEADER\n
"},{"location":"rest-references/#update-favorite-status","title":"Update favorite status","text":"PATCH /api/recipe/int:pk/favorite"},{"location":"rest-references/#parameters_1","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to be favorited or unfavorited
"},{"location":"rest-references/#headers_5","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
"},{"location":"rest-references/#responses_5","title":"Responses","text":"http code content-type response 201
application/json
\"Success favorite recipe\"
201
application/json
\"Success unfavorite recipe\"
403
application/json
`{\"detail\":\"You must use authentication header\"} 404
application/json
Not Found
"},{"location":"rest-references/#example-curl_5","title":"Example cURL","text":" curl --location --request PATCH 'host/api/recipe/1/favorite' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#create-recipe","title":"Create recipe","text":"POST /api/recipe/"},{"location":"rest-references/#payload_2","title":"Payload","text":"recipe.Recipe object{\n \"image\": file,\n \"name\": string,\n \"serves\": int,\n \"video\": file (optional),\n \"category\": <int:pk>,\n \"tag\": <int:pk>,\n \"prep_time\": int,\n}\n
"},{"location":"rest-references/#headers_6","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
multipart/form-data
Recipe object
Recipe multipart/form-data object
"},{"location":"rest-references/#responses_6","title":"Responses","text":"http code content-type response 201
application/json
{recipe.Recipe object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_6","title":"Example cURL","text":" curl --location 'localhost:8080/api/recipe/' --header 'Authorization: Token d8916a5f6cf16d2c6a87bc7461bc4680245609f0' --form 'image=@\"/path/image.jpg\"' --form 'name=\"Test recipe creation\"' --form 'serves=\"5\"' --form 'category=\"1\"' --form 'tag=1' --form 'prep_time=\"45\"'\n
"},{"location":"rest-references/#update-recipe-main-info-without-ingredients-and-steps","title":"Update recipe main info (without ingredients and steps)","text":"PUT /api/recipe/int:pk"},{"location":"rest-references/#payload_3","title":"Payload","text":"recipe.Recipe object{\n \"image\": file,\n \"name\": string,\n \"serves\": int,\n \"video\": file (optional),\n \"category\": <int:pk>,\n \"tag\": <int:pk>,\n \"prep_time\": int,\n}\n
"},{"location":"rest-references/#parameters_2","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to be updated
"},{"location":"rest-references/#headers_7","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
multipart/form-data
Recipe object
Recipe multipart/form-data object
"},{"location":"rest-references/#responses_7","title":"Responses","text":"http code content-type response 200
application/json
{recipe.Recipe object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_7","title":"Example cURL","text":" curl --location --request PUT 'host/api/recipe/1' --header 'Authorization: Token d8916a5f6cf16d2c6a87bc7461bc4680245609f0' --form 'image=@\"/path/image.jpg\"' --form 'name=\"Update name\"' --form 'serves=\"4\"' --form 'category=\"1\"' --form 'tag=\"1\"' --form 'prep_time=\"21\"'\n
"},{"location":"rest-references/#category","title":"Category","text":""},{"location":"rest-references/#get-all-categories","title":"Get all categories","text":"GET /api/recipe/trending"},{"location":"rest-references/#headers_8","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_8","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Category objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_8","title":"Example cURL","text":" curl --location 'host/api/recipe/category' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#get-all-categories-recipes","title":"Get all categories recipes","text":"GET /api/recipe/category/int:pk/recipes"},{"location":"rest-references/#parameters_3","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Category primary key
"},{"location":"rest-references/#headers_9","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_9","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Recipe objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_9","title":"Example cURL","text":" curl --location 'host/api/recipe/category/1/recipes' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#create-category","title":"Create category","text":"POST /api/recipe/category/add"},{"location":"rest-references/#payload_4","title":"Payload","text":"recipe.Category object{\n \"name\": string\n}\n
"},{"location":"rest-references/#headers_10","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_10","title":"Responses","text":"http code content-type response 201
application/json
{recipe.Category object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_10","title":"Example cURL","text":" curl --location 'host/api/recipe/category/add' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '{\"name\":\"Greek\"}'\n
"},{"location":"rest-references/#update-category","title":"Update category","text":"PUT /api/recipe/category/int:pk"},{"location":"rest-references/#payload_5","title":"Payload","text":"recipe.Category object{\n \"name\": string,\n\n}\n
"},{"location":"rest-references/#parameters_4","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Category primary key
"},{"location":"rest-references/#headers_11","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_11","title":"Responses","text":"http code content-type response 200
application/json
{recipe.Recipe object}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
404
application/json
{\"detail\":\"No Category matches the given query.\"}
"},{"location":"rest-references/#example-curl_11","title":"Example cURL","text":" curl --location --request PUT 'host/api/recipe/category/6' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --header 'Content-Type: application/json' --data '{\"name\":\"Italiano\"}'\n
"},{"location":"rest-references/#tag","title":"Tag","text":""},{"location":"rest-references/#get-all-tags","title":"Get all tags","text":"GET /api/recipe/tags"},{"location":"rest-references/#headers_12","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_12","title":"Responses","text":"http code content-type response 200
application/json
[recipe.Tag objects list]
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_12","title":"Example cURL","text":" curl --location 'host/api/recipe/tags' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#get-all-recipes-from-tag","title":"Get all recipes from tag","text":"GET /api/recipe/tag/int:pk/recipes"},{"location":"rest-references/#parameters_5","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Tag primary key
"},{"location":"rest-references/#headers_13","title":"Headers","text":"name type data type description X-Auth-Header
required
UUID
Header used for authentication with the API
"},{"location":"rest-references/#responses_13","title":"Responses","text":"http code content-type response 200
application/json
{\"count\":int,\"next\":string,\"previous\":string,\"results\":[recipe.Recipe obj list]}
403
application/json
{\"detail\":\"You must use authentication header\"}
"},{"location":"rest-references/#example-curl_13","title":"Example cURL","text":" curl --location 'host/api/recipe/tag/<int:pk>/recipes' --header 'X-Auth-Header: X_AUTH_HEADER'\n
"},{"location":"rest-references/#create-tag","title":"Create tag","text":"POST /api/recipe/tag/add"},{"location":"rest-references/#payload_6","title":"Payload","text":"recipe.Tag object{\n \"name\": string\n}\n
"},{"location":"rest-references/#headers_14","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_14","title":"Responses","text":"http code content-type response 201
application/json
{recipe.Category object}
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_14","title":"Example cURL","text":" curl --location 'host/api/recipe/tag/add' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '{\"name\":\"Summer vibes\"}'\n
"},{"location":"rest-references/#update-tag","title":"Update tag","text":"PUT /api/recipe/tag/int:pk"},{"location":"rest-references/#payload_7","title":"Payload","text":"recipe.Category object{\n \"name\": string,\n\n}\n
"},{"location":"rest-references/#parameters_6","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Tag primary key
"},{"location":"rest-references/#headers_15","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_15","title":"Responses","text":"http code content-type response 200
application/json
{recipe.Tag object}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
404
application/json
{\"detail\":\"No Category matches the given query.\"}
"},{"location":"rest-references/#example-curl_15","title":"Example cURL","text":" curl --location --request PUT 'host/api/recipe/tag/1' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --header 'Content-Type: application/json' --data '{\"name\":\"Summer Vibes\"}'\n
"},{"location":"rest-references/#ingredients","title":"Ingredients","text":"POST /api/recipe/int:pk/ingredients"},{"location":"rest-references/#payload_8","title":"Payload","text":"recipe.Igredient object list[\n {\n \"name\": \"string,\n \"quantity\": string,\n \"metric\": \"string\n },\n {\n \"name\": \"string,\n \"quantity\": string,\n \"metric\": \"string\n },\n....\n]\n
"},{"location":"rest-references/#parameters_7","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to which to link the ingredients
"},{"location":"rest-references/#headers_16","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_16","title":"Responses","text":"http code content-type response 201
application/json
[{recipe.Ingrediant object}]
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_16","title":"Example cURL","text":" curl --location 'host/api/recipe/ingredients' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '[{\"name\":\"Kasher salt\",\"quantity\":\"1/5\",\"metric\":\"tbsp\",\"recipe\":24}]'\n
"},{"location":"rest-references/#steps","title":"Steps","text":"POST /api/recipe/int:pk/steps"},{"location":"rest-references/#payload_9","title":"Payload","text":"recipe.Step object list[\n {\n \"text\": string\n },\n {\n \"text\": string\n },\n....\n]\n
"},{"location":"rest-references/#parameters_8","title":"Parameters","text":"name type data type description <int:pk>
path (required)
int
Recipe primary key to which to link the steps
"},{"location":"rest-references/#headers_17","title":"Headers","text":"name type data type description Authorization
required
Access Token
Token obtained from login endpoint example \"token 443c104be8c6daeeaf86df634e69b97668b99900\"
Content-Type
application/json
`Applicaton Json content header"},{"location":"rest-references/#responses_17","title":"Responses","text":"http code content-type response 201
application/json
[{recipe.Step object}]
400
application/json
{\"tag\":[\"Incorrect type. message\"]}
401
application/json
{\"detail\":\"Authentication credentials were not provided.\"}
"},{"location":"rest-references/#example-curl_17","title":"Example cURL","text":" curl --location 'host/api/recipe/ingredients' --header 'Authorization: token 443c104be8c6daeeaf86df634e69b97668b99900' --data '[{\"text\":\"Heat the oven\",\"recipe\":1}]'\n
"},{"location":"user-guide/","title":"User Guide","text":"The documentation for ForkAPI contains number of sections that are listed bellow.