https://github.com/evalle/study-rest
RestfulAPI application written in Flask
https://github.com/evalle/study-rest
flask python python3 restfull-api study-rest
Last synced: 6 months ago
JSON representation
RestfulAPI application written in Flask
- Host: GitHub
- URL: https://github.com/evalle/study-rest
- Owner: Evalle
- License: apache-2.0
- Created: 2017-03-22T20:54:57.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-19T20:11:12.000Z (almost 9 years ago)
- Last Synced: 2024-12-27T02:43:24.155Z (over 1 year ago)
- Topics: flask, python, python3, restfull-api, study-rest
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# study-rest
RestfulAPI with Python and Flask, see this [article](https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask) for more information.
The HTTP request methods are typically designed to affect a given resource in standard ways:
| HTTP Method | Action | Examples |
|-------------|--------|----------|
| GET | Obtain information about a resource | http://example.com/api/orders (retrieve order list) |
| GET | Obtain information about a resource | http://example.com/api/orders/123 (retrieve order #123) |
| POST | Create a new resource | http://example.com/api/orders (create a new order, from data provided with the request) |
| PUT | Update a resource | http://example.com/api/orders/123 (update order #123, from data provided with the request) |
| DELETE | Delete a resource | http://example.com/api/orders/123 (delete order #123) |
The task of designing a web service or API that adheres to the REST guidelines then becomes an exercise in identifying the resources that will be exposed and how they will be affected by the different request methods.
Our tasks resource will use HTTP methods as follows:
| HTTP Method | URI | Action |
|-------------|-----|--------|
| GET | http://[hostname]/todo/api/v1.0/tasks | Retrieve list of tasks |
| GET | http://[hostname]/todo/api/v1.0/tasks/[task_id] | Retrieve a task |
| POST | http://[hostname]/todo/api/v1.0/tasks | Create a new task |
| PUT | http://[hostname]/todo/api/v1.0/tasks/[task_id] | Retrieve list of tasks |
| DELETE | http://[hostname]/todo/api/v1.0/tasks/[task_id] | Delete a task |
To start the server, run
``` console
$ cd todo-api && chmod +x app.py && ./app.py
```
And test it via
``` console
$ curl -u evgeny:python -i http://localhost:5000/todo/api/v1.0/task
```