Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ynsrc/python-simple-rest-api
Simple REST API Example with pure Python
https://github.com/ynsrc/python-simple-rest-api
Last synced: 7 days ago
JSON representation
Simple REST API Example with pure Python
- Host: GitHub
- URL: https://github.com/ynsrc/python-simple-rest-api
- Owner: ynsrc
- License: unlicense
- Created: 2024-05-04T03:09:35.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-05-04T03:25:04.000Z (7 months ago)
- Last Synced: 2024-05-04T04:25:30.165Z (7 months ago)
- Language: Python
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple REST API with pure Python
This is an example REST API project.
## Run
```
# python server.py
```Default port is 5000, you can change it in `server.py`.
## Index
```
$ curl "http://127.0.0.1:5000/"
{
"name": "Python REST API Example",
"summary": "This is simple REST API architecture with pure Python",
"actions": [
"add",
"delete",
"list",
"search"
],
"version": "1.0.0"
}
```## List Items
```
$ curl "http://127.0.0.1:5000/list"
{
"count": 3,
"items": [
{
"id": 1000,
"name": "cat",
"description": "cat is meowing"
},
{
"id": 1001,
"name": "dog",
"description": "dog is barking"
},
{
"id": 1002,
"name": "bird",
"description": "bird is singing"
}
]
}
```## Search
```
$ curl "http://127.0.0.1:5000/search?q=d"
{
"count": 2,
"items": [
{
"id": 1001,
"name": "dog",
"description": "dog is barking"
},
{
"id": 1002,
"name": "bird",
"description": "bird is singing"
}
]
}
```## Delete Item
```
$ curl "http://127.0.0.1:5000/delete" -H "Content-Type: application/json" -d '{"id": 1001}'
{
"deleted": 1001
}
```## Add Item
```
$ curl "http://127.0.0.1:5000/add" -H "Content-Type: application/json" \
> -d '{"name": "fish", "description": "fish is swimming"}'
{
"id": 1005,
"name": "fish",
"description": "fish is swimming"
}
```## List Again
```
$ curl "http://127.0.0.1:5000/list"
{
"count": 3,
"items": [
{
"id": 1000,
"name": "cat",
"description": "cat is meowing"
},
{
"id": 1002,
"name": "bird",
"description": "bird is singing"
},
{
"id": 1003,
"name": "fish",
"description": "fish is swimming"
}
]
}
```# License
The Unlicense. Feel free to use or change it how you need.