Giter Club home page Giter Club logo

falcon-api-browse's Introduction

Falcon API Browse

This project provides a middleware for Falcon Web Framework that will render the response in an HTML form for documentation purpose. It uses the docstring from the Resource object and all the supported HTTP methods for the resource.

It is inspired by Django Rest Framework's Browsable API and is written using jinja2 templating language.

Installing

This project is currently in early stages of development. Once it is stable enough to be used by other projects, it will be provided via PyPI.

pip install falcon-api-browse

Using

Since this is a middleware for Falcon, you can use it by passing an initialized instance during Falcon App creation.

from falcon import App
from falcon_api_browse import HTMLResponseMiddleware

app = App(middleware=HTMLResponseMiddleware())

Examples

There are some runnable examples in examples/ directory.

LICENSE

This project and contents of this repo are licensed under Apache 2.0 License.

falcon-api-browse's People

Contributors

maxking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

falcon-api-browse's Issues

JSON from `resp.media` is not recognized

It seems this only works as expected if JSON is rendered via resp.text; however, the most idiomatic and succinct way of writing a JSON API is by leveraging req.get_media() and resp.media.

Test case used:

import falcon
from falcon_api_browse import HTMLResponseMiddleware


class Hello:
    def on_get(self, req, resp):
        resp.media = {'message': 'Hello, World!', 'cool': True}


app = falcon.App(middleware=[HTMLResponseMiddleware()])
app.add_route('/hello', Hello())

ASGI support

Since HTMLResponseMiddleware doesn't seem to perform any taxing I/O, one could implement ASGI support by simply wrapping the current logic via async def process_response_async(...).

Add basic sanity tests

We need to add some sanity testing to make sure that we are atleast able to avoid simple errors.

Add some CSS to the default template

The current default template is very vanilla, it could use some styling support with CSS. We could also urlize some of the urls, although it doesn't seem to work with the default urlize function for whatever reason (probably, because URLs are strings with "<url>" enclosing quotes that throws off their regex matcher.

Add runnable examples

Add atleast two basic examples for ASGI and WSGI respectively that can be run easily.

Guard against malformed json

It is possible for the response to be malformed json or something, make sure that we guard against json.JSONDecodeError.

No module named `importlib_resources`

It seems that some dependencies are required, but not listed:

  File "/tmp/test.py", line 2, in <module>
    from falcon_api_browse import HTMLResponseMiddleware
  File "/tmp/venv/lib/python3.8/site-packages/falcon_api_browse/__init__.py", line 1, in <module>
    from falcon_api_browse.middleware import HTMLResponseMiddleware
  File "/tmp/venv/lib/python3.8/site-packages/falcon_api_browse/middleware.py", line 1, in <module>
    from falcon_api_browse.views import html_response
  File "/tmp/venv/lib/python3.8/site-packages/falcon_api_browse/views.py", line 4, in <module>
    from importlib_resources import files
ModuleNotFoundError: No module named 'importlib_resources'

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.