Skip to content
This repository was archived by the owner on May 2, 2023. It is now read-only.

Get Data

Maigret Aurélien edited this page Mar 17, 2015 · 6 revisions

Decorator get_data

This "decorator" used to retrieve automatically the data in the request, and send in the object data to the method. You can see an example in project.py. Here, the POST fields "name" and "owner_id" are retrieved and added to a new object. If one of these doesn't exist in the request, an error is directly return to the client :

$> curl -X POST http://127.0.0.1:8000/api/1.0/project
{
    "error": "You must provide all mandatory fields.",
    "error_code": 400,
    "error_details": [
        "You must defined: 'name'",
        "You must defined: 'owner_id'"
    ]
}

You can also add a default content :

@get_data(["email", "password", "is_remember"], default={"is_remember": True})

Data are retrieved by default in data POST request. You can choice to do this in data GET request :

@get_data(["input"], method="GET")

Clone this wiki locally