The Open Event Server enables organizers to manage events from concerts to conferences and meetups. It offers features for events with several tracks and venues.It uses the JSON 1.0 Specification and build on top of Flask Rest Json API (for building Rest APIs) and Marshmallow (for Schema). In this blog, we will talk about how to add API for accessing and updating the Speaker Image Size on Open Event Server. The focus is on its API creation.
API Creation
For the SpeakerImageSizeDetail, we’ll make our Schema as follows
Now, let’s try to understand SpeakerImageSizeDetail.
In this feature, we are providing Admin the rights to Get and Update the SpeakerImageSizes
- kwargs[‘id’] = 2 states that Image Size model has 2 records and 1st record is used for Event Image Size and 2nd record is used for Speaker Image Size.
- decorators = (api.has_permission(‘is_admin’, methods=”PATCH”, id=”2″),) states that for Speaker Image Size, Update API is accessible to Admins only.
- methods = [‘GET’, ‘PATCH’] states that this API provides two methods i.e. GET and PATCH.
- schema = SpeakerImageSizeSchema states that the schema which is used to return the response is Speaker Image Size Schema.
- data_layer = {‘session’: db.session, ‘model’: ImageSizes} states the session and Model used to fetch the records.
Resources
- Documentation | Marshmallow : https://marshmallow-jsonapi.readthedocs.io/en/latest/
- Documentation | Flask Rest JSONAPI : http://flask-rest-jsonapi.readthedocs.io/en/latest/