<p align="center">
<a href="https://telegra.ph/BizAPI-10-18"><img src="https://raw.githubusercontent.com/turdibekjumabaev/turdibekjumabaev/refs/heads/main/host/bizapi-logo.png" alt="BizAPI"></a>
</p>
<p align="center">A Lightweight Web Framework for Python</p>
<p align="center">
<img alt="PyPI - License" src="https://img.shields.io/pypi/l/BizAPI">
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/BizAPI">
<img alt="PyPI - Status" src="https://img.shields.io/pypi/status/BizAPI">
</p>
<p align="center">
<a href="https://github.com/turdibekjumabaev/bizapi" target="_blank"><b>Source Code</b></a> and <a href="https://telegra.ph/BizAPI-10-18" target="_blank"><b>Information</b></a> about BizAPI
</p>
---
## Contents
* [Installation](#installation)
* [Quick Start](#quick-start)
* [Routing](#routing)
* [Function-Based](#function-based-routing)
* [Parameterized](#parameterized-routing)
* [Allowed Methods](#allowed-methods)
* [Class-Based](#class-based-routing)
* [Simple Router](#simple-router)
* [Templates](#templates)
* [Exception Handler](#exception-handler)
* [Custom Responses](#custom-response)
* [Middleware](#middleware)
---
## Installation
To install BizAPI, use the following command:
```
pip install BizAPI
```
---
## Quick Start
Create a simple application using BizAPI:
````python
from bizapi import BizAPI
from bizapi.types import Request, Response
app = BizAPI()
@app.route('/')
def home(request: Request, response: Response):
response.text = 'This is the home page'
````
Run the application using Gunicorn:
````shell
gunicorn main:app
````
---
## Routing
### Function-Based Routing
```python
@app.route('/')
def index(request: Request, response: Response):
response.text = "Hello World!"
```
### Parameterized Routing
```python
@app.route('/say-hello/{name}')
def sayhello(request: Request, response: Response, name: str):
response.text = f"Assalawma áleykum {name}"
```
### Allowed Methods
```python
@app.route('/article', methods=['POST'])
def create_article(request: Request, response: Response):
# Create a new article
pass
@app.route('/article', methods=['GET'])
def get_article(request: Request, response: Response):
# Get an article
pass
```
You can also use the method-specific decorators:
```python
@app.post('/article')
def create_product(request: Request, response: Response):
# Create a new article
pass
@app.get('/article')
def get_product(request: Request, response: Response):
# Get an article
pass
```
### Class-Based Routing
```python
@app.route('/article')
class Article:
def get(request: Request, response: Response):
# Get an article
pass
def post(request: Request, response: Response):
# Create a new article
pass
```
### Simple Router
```python
def create_article(request: Request, response: Response):
response.text = "A new article has been created"
app.register_route('/article', create_article, ['POST'])
```
---
## Templates
```python
from bizapi import render_template
@app.route('/hello')
def hello_page(request: Request, response: Response):
response.html = render_template('hello.html', name="John")
# Second way
@app.route('/say-hello', methods=['GET'])
def home_page(request: Request, response: Response):
response.html = render_template('hello.html', {
'title': 'Say Hello!',
'name': 'John'
})
```
`templates/hello.txt`
```html
<html>
<head><title>Hello</title></head>
<body><p>Hello, {{name}}</p></body>
</html>
```
---
## Exception Handler
Add a custom exception handler to manage errors:
```python
def on_exception(request: Request, response: Response, exc: Exception):
response.text = str(exc)
app.add_exception_handler(on_exception)
```
---
## Custom Response
BizAPI allows returning different types of responses:
```python
@app.route('/json')
def json(request: Request, response: Response):
response.json = {'message': 'Hello, World'}
```
```python
@app.route('/text')
def text(request: Request, response: Response):
response.text = "Hello World"
```
```python
@app.route('/html')
def html(request: Request, response: Response):
response.html = "<h1>Hello, World</h1>"
```
---
## Middleware
You can add middleware to process requests and responses:
```python
from bizapi.middleware import Middleware
class CustomMiddleware(Middleware):
def request(self, request: Request):
print(f"Request received: {request.path}")
def response(self, request: Request, response: Response):
print(f"Response sent for: {request.path}")
app.add_middleware(CustomMiddleware)
```
---
**License**
This project is licensed under the [MIT License](https://opensource.org/license/mit).
Raw data
{
"_id": null,
"home_page": "https://github.com/turdibekjumabaev/oneapi",
"name": "BizAPI",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9.0",
"maintainer_email": null,
"keywords": null,
"author": "Turd\u0131bek Jumabaev",
"author_email": "turdibekjumabaev05@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7e/e1/a1cddf039115dea63a23ea3a5e505208df6d3a51eb7fd187120eec74e1ab/bizapi-0.1.1.tar.gz",
"platform": null,
"description": "\r\n<p align=\"center\">\r\n <a href=\"https://telegra.ph/BizAPI-10-18\"><img src=\"https://raw.githubusercontent.com/turdibekjumabaev/turdibekjumabaev/refs/heads/main/host/bizapi-logo.png\" alt=\"BizAPI\"></a>\r\n</p>\r\n\r\n<p align=\"center\">A Lightweight Web Framework for Python</p>\r\n\r\n<p align=\"center\">\r\n <img alt=\"PyPI - License\" src=\"https://img.shields.io/pypi/l/BizAPI\">\r\n <img alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/BizAPI\">\r\n <img alt=\"PyPI - Status\" src=\"https://img.shields.io/pypi/status/BizAPI\">\r\n</p>\r\n<p align=\"center\">\r\n <a href=\"https://github.com/turdibekjumabaev/bizapi\" target=\"_blank\"><b>Source Code</b></a> and <a href=\"https://telegra.ph/BizAPI-10-18\" target=\"_blank\"><b>Information</b></a> about BizAPI\r\n</p>\r\n\r\n---\r\n\r\n## Contents\r\n\r\n * [Installation](#installation)\r\n * [Quick Start](#quick-start)\r\n * [Routing](#routing)\r\n * [Function-Based](#function-based-routing)\r\n * [Parameterized](#parameterized-routing)\r\n * [Allowed Methods](#allowed-methods)\r\n * [Class-Based](#class-based-routing)\r\n * [Simple Router](#simple-router)\r\n * [Templates](#templates)\r\n * [Exception Handler](#exception-handler)\r\n * [Custom Responses](#custom-response)\r\n * [Middleware](#middleware)\r\n\r\n---\r\n\r\n## Installation\r\n\r\nTo install BizAPI, use the following command:\r\n```\r\npip install BizAPI\r\n```\r\n\r\n---\r\n\r\n## Quick Start\r\nCreate a simple application using BizAPI:\r\n````python\r\nfrom bizapi import BizAPI\r\nfrom bizapi.types import Request, Response\r\n\r\napp = BizAPI()\r\n\r\n\r\n@app.route('/')\r\ndef home(request: Request, response: Response):\r\n response.text = 'This is the home page'\r\n\r\n````\r\nRun the application using Gunicorn:\r\n````shell\r\ngunicorn main:app\r\n````\r\n\r\n---\r\n## Routing\r\n### Function-Based Routing\r\n```python\r\n@app.route('/')\r\ndef index(request: Request, response: Response):\r\n response.text = \"Hello World!\"\r\n```\r\n\r\n### Parameterized Routing\r\n```python\r\n@app.route('/say-hello/{name}')\r\ndef sayhello(request: Request, response: Response, name: str):\r\n response.text = f\"Assalawma \u00e1leykum {name}\"\r\n```\r\n\r\n### Allowed Methods\r\n```python\r\n@app.route('/article', methods=['POST'])\r\ndef create_article(request: Request, response: Response):\r\n # Create a new article\r\n pass\r\n\r\n\r\n@app.route('/article', methods=['GET'])\r\ndef get_article(request: Request, response: Response):\r\n # Get an article\r\n pass\r\n```\r\n\r\nYou can also use the method-specific decorators:\r\n```python\r\n@app.post('/article')\r\ndef create_product(request: Request, response: Response):\r\n # Create a new article\r\n pass\r\n\r\n\r\n@app.get('/article')\r\ndef get_product(request: Request, response: Response):\r\n # Get an article\r\n pass\r\n```\r\n\r\n### Class-Based Routing\r\n```python\r\n@app.route('/article')\r\nclass Article:\r\n def get(request: Request, response: Response):\r\n # Get an article\r\n pass\r\n \r\n def post(request: Request, response: Response):\r\n # Create a new article\r\n pass\r\n```\r\n\r\n### Simple Router\r\n```python\r\ndef create_article(request: Request, response: Response):\r\n response.text = \"A new article has been created\"\r\n\r\n\r\napp.register_route('/article', create_article, ['POST'])\r\n```\r\n\r\n---\r\n\r\n## Templates\r\n\r\n```python\r\nfrom bizapi import render_template\r\n\r\n@app.route('/hello')\r\ndef hello_page(request: Request, response: Response):\r\n response.html = render_template('hello.html', name=\"John\")\r\n\r\n\r\n\r\n# Second way\r\n@app.route('/say-hello', methods=['GET'])\r\ndef home_page(request: Request, response: Response):\r\n response.html = render_template('hello.html', {\r\n 'title': 'Say Hello!',\r\n 'name': 'John'\r\n })\r\n```\r\n\r\n`templates/hello.txt`\r\n```html\r\n<html>\r\n <head><title>Hello</title></head>\r\n <body><p>Hello, {{name}}</p></body>\r\n</html>\r\n```\r\n\r\n---\r\n\r\n## Exception Handler\r\nAdd a custom exception handler to manage errors:\r\n```python\r\ndef on_exception(request: Request, response: Response, exc: Exception):\r\n response.text = str(exc)\r\n\r\n\r\napp.add_exception_handler(on_exception)\r\n```\r\n\r\n---\r\n\r\n## Custom Response\r\nBizAPI allows returning different types of responses:\r\n```python\r\n@app.route('/json')\r\ndef json(request: Request, response: Response):\r\n response.json = {'message': 'Hello, World'}\r\n```\r\n```python\r\n@app.route('/text')\r\ndef text(request: Request, response: Response):\r\n response.text = \"Hello World\"\r\n```\r\n```python\r\n@app.route('/html')\r\ndef html(request: Request, response: Response):\r\n response.html = \"<h1>Hello, World</h1>\"\r\n```\r\n\r\n---\r\n\r\n## Middleware\r\nYou can add middleware to process requests and responses:\r\n```python\r\nfrom bizapi.middleware import Middleware\r\n\r\nclass CustomMiddleware(Middleware):\r\n def request(self, request: Request):\r\n print(f\"Request received: {request.path}\")\r\n\r\n def response(self, request: Request, response: Response):\r\n print(f\"Response sent for: {request.path}\")\r\n\r\napp.add_middleware(CustomMiddleware)\r\n\r\n```\r\n\r\n---\r\n\r\n**License** \r\nThis project is licensed under the [MIT License](https://opensource.org/license/mit).\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "It is a simple and lightweight web framework built for learning and experimentation purposes.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/turdibekjumabaev/oneapi"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a3d0f10d169373bf5d6c509d5a55ee749d4fea2517f820c43754ade8b374690e",
"md5": "a95c81e6b4558367a68e9b2508e1f4be",
"sha256": "88e121c0a60db231d7cded939fb6f4c820700bfab0390db01fa31ee6e89268a9"
},
"downloads": -1,
"filename": "BizAPI-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a95c81e6b4558367a68e9b2508e1f4be",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9.0",
"size": 7609,
"upload_time": "2024-10-18T15:05:38",
"upload_time_iso_8601": "2024-10-18T15:05:38.573485Z",
"url": "https://files.pythonhosted.org/packages/a3/d0/f10d169373bf5d6c509d5a55ee749d4fea2517f820c43754ade8b374690e/BizAPI-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7ee1a1cddf039115dea63a23ea3a5e505208df6d3a51eb7fd187120eec74e1ab",
"md5": "32acd72dde62a595868728f07451655e",
"sha256": "4ec314433e25c2e0e958fa1b0d4d3bf212cc70acb6449ce8c0ee0c0acc444723"
},
"downloads": -1,
"filename": "bizapi-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "32acd72dde62a595868728f07451655e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9.0",
"size": 7389,
"upload_time": "2024-10-18T15:05:40",
"upload_time_iso_8601": "2024-10-18T15:05:40.418844Z",
"url": "https://files.pythonhosted.org/packages/7e/e1/a1cddf039115dea63a23ea3a5e505208df6d3a51eb7fd187120eec74e1ab/bizapi-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-18 15:05:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "turdibekjumabaev",
"github_project": "oneapi",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "bizapi"
}