Adding an integration
Strawberry provides a set of integrations with other libraries, such as Django, FastAPI, Flask, and more, but you can also add your own integration. This guide will show you how to do that.
Base views
Strawberry includes two base views that you can use to create your own integrations:
-
SyncBaseHTTPView
: a base view for synchronous integrations -
AsyncBaseHTTPView
: a base view for asynchronous integrations
Both views are provides the same API, with the main difference being that the
AsyncBaseHTTPView
βs methods are async.
Creating a view
To create a view, you need to create a class that inherits from either
SyncBaseHTTPView
or AsyncBaseHTTPView
and implement the get_root_value
method. Here is an example of a view that inherits from AsyncBaseHTTPView
:
The methods above are the bare minimum that you need to implement to create a view. They are all required, but you can also override other methods to change the behaviour of the view.
On top of that we also need a request adapter, hereβs the base class for the async version:
This request adapter will be used to get the request data from the request
object. You can specify the request adapter to use by setting the
request_adapter_class
attribute on the view.
Finally you need to execute the operation, the base view provides a run
method
that you can use to do that: