maxking / falcon-api-browse Goto Github PK
View Code? Open in Web Editor NEWBrowse JSON API in a HTML interface.
License: Apache License 2.0
Browse JSON API in a HTML interface.
License: Apache License 2.0
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.
It is possible for the response to be malformed json or something, make sure that we guard against json.JSONDecodeError
.
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())
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'
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(...)
.
We currently assume that the response is JSON, but it can be anything like HTML, msgpack etc. We should not make this assumption and add some guard to verify the response's content_type.
We need to add some sanity testing to make sure that we are atleast able to avoid simple errors.
Like DRF, add a http://url?format=json
query parameter that returns the json encoded response instead of the HTML page.
Add atleast two basic examples for ASGI and WSGI respectively that can be run easily.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.