PyForgeAPI is a fast and easy-to-use open source python library for developing RESTful APIs. It provides a clear and concise syntax for handling routes, requests, and responses, making the development of APIs faster and more efficient. With support for form parameters, body and route parameters, it is useful for handling different types of requests. Whether you are a beginner or an experienced developer, PyForgeAPI is a simple and powerful choice for creating robust and scalable APIs.


Keywords
api, api-rest, python, rest, vitrinedev
License
AGPL-3.0
Install
pip install PyForgeAPI==1.1.2

Documentation

PyForgeAPI

What is it and what is it for

PyForgeAPI is a fast, very simple to use and understand open source python library for developing RESTful APIs.

Installation

pip install PyForgeAPI

Exemples

Exemple for GET Route with Query Params

from PyForgeAPI import Routes, Response, Request

routes = Routes(debug=True)

@routes.get('/')
def home(req: Request, res: Response):
  # Get query params age
  age = req.query['age']
  # Recovery all persons from database with this age
  res.html("<h1>Listing all persons</h1><ul><li>A Person</li></ul>").status(200).send()

routes.run(application="Person API", port=1395)

Exemple for GET Route with Params

from PyForgeAPI import Routes, Response, Request

routes = Routes()

@routes.get('/user/:id')
def getUser(req: Request, res: Response):
  users =["#users from database"]
  for i in users:
    if i["id"] == req.params["id"]:
      return res.json(i).send()
  return res.sendStatus(404)

routes.run(application="Person API", port=1395)

Exemple for POST Route with Body

from PyForgeAPI import Routes, Response, Request

routes = Routes()

@routes.post('/user')
def createUser(req: Request, res: Response):
  user = req.body.json
  # Save user in database
  res.sendStatus( 201 )

routes.run(application="Person API", port=1395)

Exemple for PUT Route with Body

from PyForgeAPI import Routes, Response, Request

routes = Routes()

@routes.put('/user')
def createUser(req: Request, res: Response):
  user = req.body.json
  # Update user in database
  res.sendStatus(201)

routes.run(application="Person API", port=1395)

See more exemples in exemples folder

ToDo

  • Rename Request.form to Request.query
  • Print PyForgeAPI Logo again
  • Docs Page automatic
  • Error page automatic
  • If function not return response, return status code
  • If Route not exists, return status code
  • Rename variables to improve code readability
  • Remove empty spaces code from a query params
  • Fix possible infinite execution
  • Better error handling
  • Accept underscore in route params
  • Support html pages
  • CORS

Contributors

How to Contributing

Open pull request 😎