Welcome to Restful-app an API that you can use to learn more about API Testing or try out API testing tools against. The API comes with projects tests on Python (coming soon JS and JAVA). Restful-app also comes with detailed API documentation to help get you started with your API testing straight away.
The test application simulates the operation of a store. You can create users, add an item and pay for it.
For example, you can see productshop π³, that use this api
app: https://berpress.github.io/react-shop
git: https://github.com/berpress/react-shop
Language | Link | Status |
---|---|---|
Python | https://github.com/berpress/python-api-tests | |
JS | https://github.com/berpress/js-api-tests | |
TS | https://github.com/berpress/TS-api-tests | |
JAVA | not added yet, you can do this | not added |
Postman | https://github.com/berpress/postman-api-tests | β π·πΊ |
https://stores-tests-api.herokuapp.com
Swagger: https://app.swaggerhub.com/apis-docs/berpress/flask-rest-api/1.0.0
Description (English and Russian languages) https://berpress.github.io/flask-restful-api/
Also, you can use Docker and test this app local
docker push litovsky/flask-api-test
docker run -d -p 56733:80 litovsky/flask-api-test
open in browser and check
http://localhost:56733
python 3.8/requests/pytest/flask
-
Use python 3.8 +
-
Create and activate virtual environments
python3 -m venv env source env/bin/activate
-
Run in terminal
pip install -r requirements.txt
or install poetry https://python-poetry.org/, then
poetry install
-
Use pre-commit hook https://pre-commit.com/#install
-
Run tests from the folder tests with pytest or see Makefile
make +
Command | Description |
---|---|
lint | Start linting |
start | Start local app |
tests | Run all tests |
Authorization: "JWT {token}
First, learn about sequence of entity creation
- πͺ Create user POST /register
- π Auth with data from step 1 POST /auth.You will get auth token
- π Add user info POST /user_info. This action is required to pay for the item.
- πͺ Add store POST /store
- π Add item POST /item to store from step 4
- π΅ Increase the balance for the user POST /balance.
- π³ Pay item POST /pay
See swagger https://app.swaggerhub.com/apis-docs/berpress/flask-rest-api/1.0.0
or
Documentation
Register new user
POST
https://stores-tests-api.herokuapp.com/register
Example
curl -X POST
https://stores-tests-api.herokuapp.com/register \
-H 'Content-Type: application/json' \
-d '{
"username" : "admin",
"password" : "Password11"
}'
Body
Field | Type | Description |
---|---|---|
password | str | Make a user password |
username | str | Make a user username |
Response
Status code 201
{'message': 'User created successfully.', 'uuid': 1}
Field | Type | Description |
---|---|---|
message | str | Success message |
uuid | str | user uuid |
Authentication user
POST
https://stores-tests-api.herokuapp.com/auth
Example
curl -X POST
https://stores-tests-api.herokuapp.com/auth \
-H 'Content-Type: application/json' \
-d '{
"username" : "admin",
"password" : "Password11"
}'
Body
Field | Type | Description |
---|---|---|
password | str | User password |
username | str | User username |
Response
Status code 200
'{"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."}'
Field | Type | Description |
---|---|---|
access_token | str | Access token |
Add user information
POST
https://stores-tests-api.herokuapp.com/user_info/{user_id}
Example
curl -X POST
https://stores-tests-api.herokuapp.com/user_info/1 \
-H 'Content-Type: application/json' \
-d '{
"phone": "122434",
"email": "[email protected]",
"address": {
"city": "Kazan",
"street": "Limonova",
"home_number": "11"
},
}'
Body
Field | Type | Description |
---|---|---|
phone | str | User phone |
str | User email | |
address | Object | Address object |
address/city | str | User city |
address/street | str | User street |
address/home_number | str | User home number |
Response
Status code 200
{"message":"User info created successfully."}
Field | Type | Description |
---|---|---|
message | str | Result user info action |
Get user information
GET
https://stores-tests-api.herokuapp.com/user_info/{user_id}
Example
curl -X GET
https://stores-tests-api.herokuapp.com/user_info/1 \
-H 'Content-Type: application/json' \'
Response
Status code 200
{'city': 'NY', 'street': 'Louge street', 'userID': 1, 'phone': '77777', 'email': '[email protected]'}
Field | Type | Description |
---|---|---|
city | str | User city |
street | str | User street |
phone | str | User phone |
str | User email |
Delete user information
DELETE
https://stores-tests-api.herokuapp.com/user_info/{user_id}
Example
curl -X DELETE
https://stores-tests-api.herokuapp.com/auth \
-H 'Content-Type: application/json' \
Response
Status code 200
{"message":"User info deleted."}
Field | Type | Description |
---|---|---|
message | str | Result user info action |
Edit user information
PUT
https://stores-tests-api.herokuapp.com/user_info/{user_id}
Example
curl -X PUT
https://stores-tests-api.herokuapp.com/auth \
-H 'Content-Type: application/json' \
-d '{
"phone": "122434",
"email": "[email protected]",
"address": {
"city": "Kazan",
"street": "Limonova",
"home_number": "11"
},
}'
Body
Field | Type | Description |
---|---|---|
phone | str | User phone |
str | User email | |
address | Object | Address object |
address/city | str | User city |
address/street | str | User street |
address/home_number | str | User home number |
Response
Status code 200
{'city': 'NY', 'street': 'Louge street', 'userID': 1, 'phone': '77777', 'email': '[email protected]'}
Field | Type | Description |
---|---|---|
city | str | User city |
street | str | User street |
phone | str | User phone |
str | User email |
Add store
POST
https://stores-tests-api.herokuapp.com/store/{name_store}
Example
curl -X POST
https://stores-tests-api.herokuapp.com/store/cars \
-H 'Content-Type: application/json' \
Response
Status code 200
{"name": "cars", "items": []}
Field | Type | Description |
---|---|---|
name | str | Store name |
items | list | List of store items |
Get store
GET
https://stores-tests-api.herokuapp.com/store/{name_store}
Example
curl -X POST
https://stores-tests-api.herokuapp.com/store/cars \
-H 'Content-Type: application/json' \
Response
Status code 200
{"name": "cars", "items": []}
Field | Type | Description |
---|---|---|
name | str | Store name |
items | list | List of store items |
Add item
POST
https://stores-tests-api.herokuapp.com/item/{name_item}
Example
curl -X POST
https://stores-tests-api.herokuapp.com/item/bmw \
-H 'Content-Type: application/json' \
-d '{
"price": 2000,
"store_id": 1
}'
Body
Field | Type | Description |
---|---|---|
price | int | Item price |
store_id | int | Store id |
Response
Status code 200
{"name": "cars", "items": []}
Field | Type | Description |
---|---|---|
name | str | Store name |
items | list | List of store items |
Change item
PUT
https://stores-tests-api.herokuapp.com/item/{name_item}
Example
curl -X PUT
https://stores-tests-api.herokuapp.com/item/bmw \
-H 'Content-Type: application/json' \
-d '{
"price": 2000,
"store_id": 1
}'
Body
Field | Type | Description |
---|---|---|
price | int | Item price |
store_id | int | Store id |
Response
Status code 200
{"name": "bmw", "price": 1947.0, "itemID": 1}
Field | Type | Description |
---|---|---|
name | str | Item name |
price | int | Item price |
itemID | int | Item id |
Get item
GET
https://stores-tests-api.herokuapp.com/item/{name_item}
Example
curl -X GET
https://stores-tests-api.herokuapp.com/item/bmw \
-H 'Content-Type: application/json' \
Response
Status code 200
{"name": "bmw", "price": 1947.0, "itemID": 1}
Field | Type | Description |
---|---|---|
name | str | Item name |
price | int | Item price |
itemID | int | Item id |
Get items
GET
https://stores-tests-api.herokuapp.com/items
Example
curl -X GET
https://stores-tests-api.herokuapp.com/items
-H 'Content-Type: application/json' \
Response
Status code 200
[{"name": "bmw", "price": 1947.0, "itemID": 1}]
Field | Type | Description |
---|---|---|
name | str | Item name |
price | int | Item price |
itemID | int | Item id |
User balance
POST
https://stores-tests-api.herokuapp.com/balance/{user_id}
Example
curl -X POST
https://stores-tests-api.herokuapp.com/balance/1 \
-H 'Content-Type: application/json' \
-d '{
"balance" : 2000,
}'
Body
Field | Type | Description |
---|---|---|
balance | int | Add money for user |
Response
Status code 201
{"message": "User balance has been updated. New balance is 4106.0"}
Field | Type | Description |
---|---|---|
message | str | Success message |
Get user balance
GET
https://stores-tests-api.herokuapp.com/balance/{user_id}
Example
curl -X GET
https://stores-tests-api.herokuapp.com/balance/1 \
-H 'Content-Type: application/json' \
Response
Status code 200
{"message": "User balance has been updated. New balance is 4106.0"}
Field | Type | Description |
---|---|---|
message | str | Success message |
Buying a product
POST
https://stores-tests-api.herokuapp.com/pay/{user_id}
Example
curl -X POST
https://stores-tests-api.herokuapp.com/pay/1 \
-H 'Content-Type: application/json' \
-d '{
"itemId" : 1,
}'
Body
Field | Type | Description |
---|---|---|
itemId | int | item id |
Response
Status code 200
{"message": "Payment was successful", "balance": 2159.0, "name": "bmw", "price": 1947.0}
Field | Type | Description |
---|---|---|
message | str | Success message |
balance | int | New balance |
name | str | Name of the purchased product |