A
A
akrapovich2019-02-11 17:00:08
Django
akrapovich, 2019-02-11 17:00:08

Django Rest Framework: What is SCHEMAS used for?

I'm reading the DRF manual and I can't figure out what the ability to generate Schemas is for ? It says what is used by dynamic client libraries that can interact with the API. Who can provide an example of use?

{
    "_type": "document",
    "_meta": {
        "url": "http://127.0.0.1:8000/schema/",
        "title": "Pastebin API"
    },
    "snippets": {
        "list": {
            "_type": "link",
            "url": "/snippets/",
            "action": "get",
            "description": "This viewset automatically provides `list`, `create`, `retrieve`,\n`update` and `destroy` actions.\n\nAdditionally we also provide an extra `highlight` action.",
            "fields": [
                {
                    "name": "page",
                    "location": "query",
                    "schema": {
                        "_type": "integer",
                        "title": "Page",
                        "description": "A page number within the paginated result set."
                    }
                }
            ]
        },
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Chichak, 2019-02-28
@ilya_chch

This is used to avoid hardcoding form fields.
For example, if the model changes, it requires a front change to add, change, or remove a field.
And with the help of the scheme, this process can be automated. That is, before creating the form, a scheme is obtained, fields and their types are taken from it, and certain inputs are built.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question