Warning: Bocadillo is now UNMAINTAINED. Users are recommended to migrate to a supported alternative, such as Starlette or FastAPI. Please see #344 for more information.

bocadillo.views

View

View(self, obj:Any, methods:List[str]=None)

This class defines how all HTTP views are represented internally.

Views objects should not be created directly. Instead, use from_handler or from_obj.

HTTP methods are mapped to handlers, i.e. methods of a View object.

The following handlers are supported:

  • .get(req, res, **kwargs)
  • .post(req, res, **kwargs)
  • .put(req, res, **kwargs)
  • .patch(req, res, **kwargs)
  • .delete(req, res, **kwargs)
  • .head(req, res, **kwargs)
  • .options(req, res, **kwargs)
  • .handle(req, res, **kwargs)

.handle() is special: if defined, it overrides all others.