All Projects → vlakir → cleanapi

vlakir / cleanapi

Licence: GPL-3.0 license
Pretty tornado wrapper for making lightweight REST API services

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to cleanapi

sticker
Sticker is a powerful yet boilerplate-free alternative to writing your web API.
Stars: ✭ 26 (+0%)
Mutual labels:  tornado, api-rest
diffido
Watch web pages for changes
Stars: ✭ 19 (-26.92%)
Mutual labels:  tornado
api sof
Tutorial para acessar a API do Sistema de Orçamento e Finanças _SOF da cidade de São Paulo, utilizando Python e a biblioteca Pandas, realizar análises e salvar arquivo CSV/Excel
Stars: ✭ 31 (+19.23%)
Mutual labels:  api-rest
rabbitChat
A Chat-Server/Chat-System based on AMQP protocol(RabbitMQ) + AMQP Python Client(PIKA) + Websockets(SockJS) + Async Python Server(Tornado)
Stars: ✭ 53 (+103.85%)
Mutual labels:  tornado
rest-api
Laravel restfull api boilerplate
Stars: ✭ 57 (+119.23%)
Mutual labels:  api-rest
covidAPI
Coronavirus API for Current cases by country COVID-19
Stars: ✭ 600 (+2207.69%)
Mutual labels:  api-rest
pait
Python Modern API Tools, fast to code
Stars: ✭ 24 (-7.69%)
Mutual labels:  tornado
saisoku
Saisoku is a Python module that helps you build complex pipelines of batch file/directory transfer/sync jobs.
Stars: ✭ 40 (+53.85%)
Mutual labels:  tornado
reedelk-runtime
Reedelk Runtime Platform Community Edition
Stars: ✭ 25 (-3.85%)
Mutual labels:  api-rest
kdniao python
快递鸟 kdniao python sdk, with tornado async & asyncio http client support.
Stars: ✭ 25 (-3.85%)
Mutual labels:  tornado
openbrewerydb-rails-api
Official v1 Open Brewery DB REST API built with Ruby on Rails
Stars: ✭ 17 (-34.62%)
Mutual labels:  api-rest
smockin
Dynamic API, S3 & Mail mocking for web, mobile & microservice development.
Stars: ✭ 74 (+184.62%)
Mutual labels:  api-rest
The-Code-Bending-Dictionary
🧚🏽‍♀️ learn tech vocab in a friendly way 🧚🏽‍♀️ CONTRIBUTIONS WELCOME! 🔥
Stars: ✭ 19 (-26.92%)
Mutual labels:  api-rest
tornado-upload
File Upload Application for Tornado
Stars: ✭ 41 (+57.69%)
Mutual labels:  tornado
buscador-ao
Ponto de obtenção de informações públicas de Angola
Stars: ✭ 21 (-19.23%)
Mutual labels:  api-rest
nestjs-api-mongoose
Collection example apps with NestJS and Typeorm, Sequelize, Mongodb, PostgreSQL, MySQL, GraphQL, Mercurius, etc. for the NestJS community 😻
Stars: ✭ 153 (+488.46%)
Mutual labels:  api-rest
laravel5-jokes-api-with-jwt-and-pagination
Laravel5 Full Fledged API with JWT auth
Stars: ✭ 15 (-42.31%)
Mutual labels:  api-rest
dart-express
Express-like HTTP framework written in Dart
Stars: ✭ 34 (+30.77%)
Mutual labels:  api-rest
nuada-cli
Nuada CLI was designed to improve your development experience by using ExpressJS and Mongoose tools.
Stars: ✭ 19 (-26.92%)
Mutual labels:  api-rest
vemdezapbe.be
Vem de zap bb 😏😊😂
Stars: ✭ 33 (+26.92%)
Mutual labels:  api-rest

PyPi Version

CleanAPI

Pretty tornado wrapper for making lightweight REST API services


Installation:

pip install cleanapi

Example:

Project folders structure:

.
├── handlers
│   └── simple_handler.py
├── log
├── ssl
│   ├── ca.csr
│   └── ca.key
├── static_html
│   └── index.html
└── server_example.py

server_example.py

from cleanapi import server

if __name__ == '__main__':
    # uses http protocol
    server.start('http', 8080, '/', './handlers', './static_html')

    # # uses https protocol
    # server.start('https', 8443, '/', './handlers', './static_html',
    #              path_to_ssl='./ssl', ssl_certfile_name='ca.csr', ssl_keyfile_name='ca.key')

simple_handler.py

from cleanapi.server import BaseHandler

url_tail = '/example.json'


# noinspection PyAbstractClass
class Handler(BaseHandler):
    """
    Test API request handler
    """
    async def get(self):
        self.set_status(200)
        self.write({'status': 'working'})

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Cleanapy demo</title>
  <link rel="icon" href="/favicon.ico" type="image/x-icon" />
 </head>
<body>

<h1>Cleanapy demo page</h1>

<p>Everything OK</p>

</body>
</html>

You also may put 'favicon.ico' file to the 'static_html' folder, but it is not necessary.

Then you can test server responses on http://localhost:8080 and http://localhost:8080/example.json

See log/cleanapi.log for information about externel access to the server


Example with PydanticHandler:

pydantic_handler.py

from cleanapi.server import PydanticHandler
from pydantic import BaseModel, validator, NonNegativeInt
from typing import Optional, List


url_tail = '/pydantic.json'


class PydanticRequest(BaseModel):
    """
    Pydantic dataclass for request
    """
    foo: NonNegativeInt
    bar: NonNegativeInt

    @validator('foo', 'bar')
    def _validate_foo_bar(cls, val: str):
        if val == 666:
            raise ValueError(f'Values of foo and bar should not be equal to 666')
        return val


class PydanticResponse(BaseModel):
    """
    Pydantic dataclass for response
    """
    summ: Optional[NonNegativeInt]
    errors: Optional[List[dict]]


# noinspection PyAbstractClass
class Handler(PydanticHandler):
    """
    Example of using PydanticHandler
    """
    request_dataclass = PydanticRequest
    result_dataclass = PydanticResponse

    # noinspection PyUnusedLocal
    def process(self, request: request_dataclass) -> result_dataclass:
        """
        What the handler should do
        :param request: incoming request
        :type request: request_dataclass
        :return: processing result
        :type: result_data class
        """
        result = PydanticResponse(summ=request.foo + request.bar, errors=[])

        if result.summ > 1000:
            raise ValueError('The sum of foo and bar is more than 1000')

        return result

    def if_exception(self, errors: list) -> None:
        """
        What to do if an exception was thrown
        :param errors: list of errors
        :type errors: list
        """
        self.set_status(400)
        self.write({'errors': errors})
        return

You can not test it with a browser because of POST method using. You have to use a program like Postman or some custom util like my pynger.py

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].