-
Notifications
You must be signed in to change notification settings - Fork 73
HTTP Methods
Thomas Pollet edited this page Oct 3, 2022
·
4 revisions
You can limit the http methods that are allowd by declaring the http_methods class attribute:
class Person(BaseModel):
http_methods = ["get"]It is possible to customize the PATCH and POST methods of an instance by overriding the SAFRSBase _s_patch and _s_post methods. For example:
def _s_patch(self, *args, **kwargs):
"""
Verify access when updating a user
"""
print(kwargs)
if g.user is self or g.user.role == "admin":
return SAFRSBase._s_patch(self, *args, **kwargs)
raise AuthorizationError("Not allowed")The kwargs dictionary will contain the jsonapi data.attributes.
An _s_post override should be a classmethod (POST is used to create an instance so an instance does not yet exist when this method is called)
@classmethod
def _s_post(cls, *args, **kwargs):
print(kwargs)
result = cls(*args, **kwargs)
print(result)
return result- Home
- Installation
- Quickstart (Flask)
- Quickstart (FastAPI)
- JSON:API Basics
- Relationships and Includes
- Filtering
- Sorting, Pagination, and Sparse Fieldsets
- Content Types and Errors
- Bulk Requests
- RPC / Custom Methods
- Customization
- Security and Access Control
- Stateless Endpoints / JABase
- Performance
- Examples
- Existing Databases (Legacy)
- PostGIS / GeoAlchemy2
- Docker / Deployment
- Troubleshooting
- Reference: SAFRSBase
- Reference: SAFRSBase Customization