thnee / flask-api-framework Goto Github PK
View Code? Open in Web Editor NEWFramework for building semantically correct HTTP API’s in Flask.
Home Page: https://flask-api-framework.rtfd.io
License: BSD 3-Clause "New" or "Revised" License
Framework for building semantically correct HTTP API’s in Flask.
Home Page: https://flask-api-framework.rtfd.io
License: BSD 3-Clause "New" or "Revised" License
Since schema instance is assigned to the view, the same instance is reused for every request to the view. flask-api-framework
uses marshmallow.Schema.load
method to deserialize passed data to a schema instance. It means that missing non-required fields, dynamically assigned attributes and other instance attributes (eg schema context
) will not be re-loaded. It may lead to the situation when a view can access schema data from the previous requests.
Here is an example:
import base64
from marshmallow import Schema, fields, validates
class MySchema(Schema):
event = fields.String()
b64_message = fields.String()
@validates("b64_message")
def validates_message(self, value):
self.context["decoded_message"] = base64.b64decode(value).decode()
# assign schema instance to the view class
s = MySchema()
# handling first request
request_data = {"event": "first_event", "b64_message": base64.b64encode("hey".encode()).decode()}
loaded_data = s.load(data=request_data)
print(s.context["decoded_message"]) # prints "hey" which is correct
# handling second request
request_data = {"event": "second_event"}
loaded_data = s.load(data=request_data)
print(s.context["decoded_message"]) # prints "hey" but a KeyError is expected
A possible solution is to assign schema class to the view and create a new schema instance every time before calling marshmallow.Schema.load
.
As an alternative, marshmallow.Schema
class can be extended with a custom load_new
method that returns a new schema instance.
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.