GithubHelp home page GithubHelp logo

mikeywaites / flask-arrested Goto Github PK

View Code? Open in Web Editor NEW
39.0 8.0 5.0 274 KB

Flask-Arrested: A Framework For Rapidly Building REST APIs with Flask.

Home Page: https://arrested.readthedocs.org

License: MIT License

Python 97.88% Shell 0.19% Gherkin 1.93%
python rest-api flask flask-api flask-sqlalchemy serialization marshalling

flask-arrested's Introduction

Flask-Arrested: A Framework For Rapidly Building REST APIs with Flask.

image

image

image

image

image

image

image


Introducing Arrested

Take the pain out of REST API creation with Arrested - batteries included for quick wins, highly extensible for specialist requirements.

from arrested import ArrestedAPI, Resource, Endpoint, GetListMixin, CreateMixin,
from example.models import db, Character

api_v1 = ArrestedAPI(url_prefix='/v1')

characters_resource = Resource('characters', __name__, url_prefix='/characters')


class CharactersIndexEndpoint(Endpoint, GetListMixin, CreateMixin):

    name = 'list'
    many = True

    def get_objects(self):

        characters = db.session.query(Character).all()
        return characters

    def save_object(self, obj):

        character = Character(**obj)
        db.session.add(character)
        db.session.commit()
        return character


characters_resource.add_endpoint(CharactersIndexEndpoint)
api_v1.register_resource(characters_resource)

Flask-Arrested Features

Arrested is a framework for rapidly building REST API's with Flask.

  • Un-Opinionated: Let's you decide "the best way" to implement your REST API.
  • Battle Tested: In use across many services in a production environment.
  • Batteries Included! Arrested ships with built in support for popular libraries such as SQLAlchemy, Kim and Marshmallow. Using something different or have your own tooling you need to support? Arrested provides a rich API that can be easily customised!
  • Supports any storage backends: Want to use "hot new database technology X?" No problem! Arrested can be easily extended to handle all your data needs.
  • Powerful middleware system - Inject logic at any step of the request/response cycle

๐Ÿš€ Get started in under a minute..

Use the Flask-Arrested cookie cutter to create a basic API to get you started in 4 simple commands. https://github.com/mikeywaites/arrested-cookiecutter.

$ cookiecutter gh:mikeywaites/arrested-cookiecutter
$ cd arrested-users-api
$ docker-compose up -d api
$ curl -u admin:secret localhost:8080/v1/users | python -m json.tool

The User Guide

Get started with Flask-Arrested using the quickstart user guide or take a look at the in-depth API documentation.

https://arrested.readthedocs.org.

flask-arrested's People

Contributors

jackqu7 avatar mikeywaites avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-arrested's Issues

Hooks defined on an Endpoint are not called.

Investigate @mrkmcknz suggestion that hooks are not being called when they are defined on an endpoint.

my_resource = Resource('test', __name__, url_prefix='/test', before_all_hooks=[resource_hook])

class MyEndpoint(Endpoint):
    before_all_hooks = [my_hook]

my_resource.add_endpoint(MyEndpoint)

A request handled by MyEndpoint appears as though only resource_hook will be called.

No way to pass additional kwargs to serialize() or marshal()

In KimResponseHandler:
return self.mapper(obj=data, raw=self.raw, **self.mapper_kwargs).serialize( role=self.role )

This allows you to pass custom kwargs to the mapper's __init__ method, but not to serialize itself. Examples of such kwargs are deferred_role

Registering resources using add_url_rule() does not automatically prefix urls

In some cases we might wan't to manually mount handlers to urls using the standard functionality provided by the flask Blueprint object.

For example, flask-oauthlib provides a view that handles the OAuth authentication flow. It's a little confusing to the user that the normal url_prefixing that occurs when mounting resources does not occur when using the lower level blueprint methods.

Manually Mounting Views on Resources

oauth_resource = Resource('api_v3.authentiation', __name__, url_prefix='/oauth')
oauth_resource.add_url_rule('/authorization', view_func=authorize, methods=['GET'])

Currently this would result in the authorize func being mounted on the url /authorize and not /v3/oauth/authorize as you might expect.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.