I create a REST-API with starlette and just discoverd
HTTPEndpoint to use for a route that will have 4 http-Methods. So I thougth it would be cleaner to use an HTTPEndpoint-Class to do so. What I´m trying to do is actually just some CRUDing so I thought I can put the code, that fetches objects from the storage somehow seperate and reuse it in alle 4 methods (get, post, put, delete). All the fetching is done in a
try/except block witch is returning some 4xx status-codes if the request IDs are not there or malformed:
try: self.id = UUID(request.path_params['nodeID']) except ValueError: return Response(status_code=400) try: self.node = tree.node(self.id) except KeyError: return Response(status_code=404)
But with this solution I need to call this code somehow through the
starlette.endpoints.HTTPEndpoint.dispatcher so that the returning Response-Objects get actually executed or
raise HTTPException which I need to catch again.
What I had in mind fist is to overright
__init__() and do all this object-fetching there but
__init__() must not retrun the Respons-Obj neither.
So how is it ment to work within a
HTTPEndpoint class to share some code between the http-method functions?