Skip to content

ynsrc/python-simple-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy