| 1 |
<style> |
| 2 |
.promo li a { |
| 3 |
float: left; |
| 4 |
width: 130px; |
| 5 |
height: 20px; |
| 6 |
text-align: center; |
| 7 |
margin: 10px 30px; |
| 8 |
padding: 150px 0 0 0; |
| 9 |
background-position: 0 50%; |
| 10 |
background-size: 130px auto; |
| 11 |
background-repeat: no-repeat; |
| 12 |
font-size: 120%; |
| 13 |
color: black; |
| 14 |
} |
| 15 |
.promo li { |
| 16 |
list-style: none; |
| 17 |
} |
| 18 |
</style> |
| 19 |
|
| 20 |
# Django REST framework 3.6 |
| 21 |
|
| 22 |
The 3.6 release adds two major new features to REST framework. |
| 23 |
|
| 24 |
1. Built-in interactive API documentation support. |
| 25 |
2. A new JavaScript client library. |
| 26 |
|
| 27 |
 |
| 28 |
|
| 29 |
*Above: The interactive API documentation.* |
| 30 |
|
| 31 |
--- |
| 32 |
|
| 33 |
## Funding |
| 34 |
|
| 35 |
The 3.6 release would not have been possible without our [backing from Mozilla](mozilla-grant.md) to the project, and our [collaborative funding model][funding]. |
| 36 |
|
| 37 |
If you use REST framework commercially and would like to see this work continue, |
| 38 |
we strongly encourage you to invest in its continued development by |
| 39 |
**[signing up for a paid plan][funding]**. |
| 40 |
|
| 41 |
<ul class="premium-promo promo"> |
| 42 |
<li><a href="https://www.rover.com/careers/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rover_130x130.png)">Rover.com</a></li> |
| 43 |
<li><a href="https://sentry.io/welcome/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/sentry130.png)">Sentry</a></li> |
| 44 |
<li><a href="https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/stream-130.png)">Stream</a></li> |
| 45 |
<li><a href="https://machinalis.com/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/Machinalis130.png)">Machinalis</a></li> |
| 46 |
<li><a href="https://rollbar.com" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rollbar.png)">Rollbar</a></li> |
| 47 |
<li><a href="https://micropyramid.com/django-rest-framework-development-services/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/mp-text-logo.png)">MicroPyramid</a></li> |
| 48 |
</ul> |
| 49 |
<div style="clear: both; padding-bottom: 20px;"></div> |
| 50 |
|
| 51 |
*Many thanks to all our [sponsors][sponsors], and in particular to our premium backers, [Rover](https://www.rover.com/careers/), [Sentry](https://sentry.io/welcome/), [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf), [Machinalis](https://machinalis.com/), [Rollbar](https://rollbar.com), and [MicroPyramid](https://micropyramid.com/django-rest-framework-development-services/).* |
| 52 |
|
| 53 |
--- |
| 54 |
|
| 55 |
## Interactive API documentation |
| 56 |
|
| 57 |
REST framework's new API documentation supports a number of features: |
| 58 |
|
| 59 |
* Live API interaction. |
| 60 |
* Support for various authentication schemes. |
| 61 |
* Code snippets for the Python, JavaScript, and Command Line clients. |
| 62 |
|
| 63 |
The `coreapi` library is required as a dependency for the API docs. Make sure |
| 64 |
to install the latest version (2.3.0 or above). The `pygments` and `markdown` |
| 65 |
libraries are optional but recommended. |
| 66 |
|
| 67 |
To install the API documentation, you'll need to include it in your projects URLconf: |
| 68 |
|
| 69 |
from rest_framework.documentation import include_docs_urls |
| 70 |
|
| 71 |
API_TITLE = 'API title' |
| 72 |
API_DESCRIPTION = '...' |
| 73 |
|
| 74 |
urlpatterns = [ |
| 75 |
... |
| 76 |
path('docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION)) |
| 77 |
] |
| 78 |
|
| 79 |
Once installed you should see something a little like this: |
| 80 |
|
| 81 |
 |
| 82 |
|
| 83 |
We'll likely be making further refinements to the API documentation over the |
| 84 |
coming weeks. Keep in mind that this is a new feature, and please do give |
| 85 |
us feedback if you run into any issues or limitations. |
| 86 |
|
| 87 |
For more information on documenting your API endpoints see the ["Documenting your API"][api-docs] section. |
| 88 |
|
| 89 |
--- |
| 90 |
|
| 91 |
## JavaScript client library |
| 92 |
|
| 93 |
The JavaScript client library allows you to load an API schema, and then interact |
| 94 |
with that API at an application layer interface, rather than constructing fetch |
| 95 |
requests explicitly. |
| 96 |
|
| 97 |
Here's a brief example that demonstrates: |
| 98 |
|
| 99 |
* Loading the client library and schema. |
| 100 |
* Instantiating an authenticated client. |
| 101 |
* Making an API request using the client. |
| 102 |
|
| 103 |
**index.html** |
| 104 |
|
| 105 |
<html> |
| 106 |
<head> |
| 107 |
<script src="/static/rest_framework/js/coreapi-0.1.0.js"></script> |
| 108 |
<script src="/docs/schema.js"></script> |
| 109 |
<script> |
| 110 |
const coreapi = window.coreapi |
| 111 |
const schema = window.schema |
| 112 |
|
| 113 |
// Instantiate a client... |
| 114 |
let auth = coreapi.auth.TokenAuthentication({scheme: 'JWT', token: 'xxx'}) |
| 115 |
let client = coreapi.Client({auth: auth}) |
| 116 |
|
| 117 |
// Make an API request... |
| 118 |
client.action(schema, ['projects', 'list']).then(function(result) { |
| 119 |
alert(result) |
| 120 |
}) |
| 121 |
</script> |
| 122 |
</head> |
| 123 |
</html> |
| 124 |
|
| 125 |
The JavaScript client library supports various authentication schemes, and can be |
| 126 |
used by your project itself, or as an external client interacting with your API. |
| 127 |
|
| 128 |
The client is not limited to usage with REST framework APIs, although it does |
| 129 |
currently only support loading CoreJSON API schemas. Support for Swagger and |
| 130 |
other API schemas is planned. |
| 131 |
|
| 132 |
For more details see the [JavaScript client library documentation][js-docs]. |
| 133 |
|
| 134 |
## Authentication classes for the Python client library |
| 135 |
|
| 136 |
Previous authentication support in the Python client library was limited to |
| 137 |
allowing users to provide explicit header values. |
| 138 |
|
| 139 |
We now have better support for handling the details of authentication, with |
| 140 |
the introduction of the `BasicAuthentication`, `TokenAuthentication`, and |
| 141 |
`SessionAuthentication` schemes. |
| 142 |
|
| 143 |
You can include the authentication scheme when instantiating a new client. |
| 144 |
|
| 145 |
auth = coreapi.auth.TokenAuthentication(scheme='JWT', token='xxx-xxx-xxx') |
| 146 |
client = coreapi.Client(auth=auth) |
| 147 |
|
| 148 |
For more information see the [Python client library documentation][py-docs]. |
| 149 |
|
| 150 |
--- |
| 151 |
|
| 152 |
## Deprecations |
| 153 |
|
| 154 |
### Updating coreapi |
| 155 |
|
| 156 |
If you're using REST framework's schema generation, or want to use the API docs, |
| 157 |
then you'll need to update to the latest version of coreapi. (2.3.0) |
| 158 |
|
| 159 |
### Generating schemas from Router |
| 160 |
|
| 161 |
The 3.5 "pending deprecation" of router arguments for generating a schema view, such as `schema_title`, `schema_url` and `schema_renderers`, have now been escalated to a |
| 162 |
"deprecated" warning. |
| 163 |
|
| 164 |
Instead of using `DefaultRouter(schema_title='Example API')`, you should use the `get_schema_view()` function, and include the view explicitly in your URL conf. |
| 165 |
|
| 166 |
### DjangoFilterBackend |
| 167 |
|
| 168 |
The 3.5 "pending deprecation" warning of the built-in `DjangoFilterBackend` has now |
| 169 |
been escalated to a "deprecated" warning. |
| 170 |
|
| 171 |
You should change your imports and REST framework filter settings as follows: |
| 172 |
|
| 173 |
* `rest_framework.filters.DjangoFilterBackend` becomes `django_filters.rest_framework.DjangoFilterBackend`. |
| 174 |
* `rest_framework.filters.FilterSet` becomes `django_filters.rest_framework.FilterSet`. |
| 175 |
|
| 176 |
--- |
| 177 |
|
| 178 |
## What's next |
| 179 |
|
| 180 |
There are likely to be a number of refinements to the API documentation and |
| 181 |
JavaScript client library over the coming weeks, which could include some of the following: |
| 182 |
|
| 183 |
* Support for private API docs, requiring login. |
| 184 |
* File upload and download support in the JavaScript client & API docs. |
| 185 |
* Comprehensive documentation for the JavaScript client library. |
| 186 |
* Automatically including authentication details in the API doc code snippets. |
| 187 |
* Adding authentication support in the command line client. |
| 188 |
* Support for loading Swagger and other schemas in the JavaScript client. |
| 189 |
* Improved support for documenting parameter schemas and response schemas. |
| 190 |
* Refining the API documentation interaction modal. |
| 191 |
|
| 192 |
Once work on those refinements is complete, we'll be starting feature work |
| 193 |
on realtime support, for the 3.7 release. |
| 194 |
|
| 195 |
[sponsors]: https://fund.django-rest-framework.org/topics/funding/#our-sponsors |
| 196 |
[funding]: https://opencollective.com/django-rest-framework |
| 197 |
[api-docs]: ../topics/documenting-your-api.md |
| 198 |
[js-docs]: https://github.com/encode/django-rest-framework/blob/3.14.0/docs/topics/api-clients.md#javascript-client-library |
| 199 |
[py-docs]: https://github.com/encode/django-rest-framework/blob/3.14.0/docs/topics/api-clients.md#python-client-library |