Explore the World's Best Ideas
Join today and uncover 100+ curated journeys from 50+ topics. Unlock access to our mobile app with extensive features.
This article is recommended to be read having some prerequisites. You should be familiar with HTTP Methods and some basics regarding Django.
If that's not your case, please check the resources below before proceeding with the article:
1
33 reads
Tastypie is a framework for Django that helps programmers to develop RESTful APIs on top of their already existing projects.
1
19 reads
As a general rule, each group of endpoints is seen as a resource. When I say a group of endpoints I mean a collection of HTTP methods on a specific route (e.g. GET, POST and DELETE on /api/entity).
These resources have a lot of features, which include allowing you to access the endpoint with specific HTTP methods, permitting access only if you are authenticated, paginating the results etc.
1
14 reads
In Tastypie, there are 3 types of endpoints:
List endpoints return a list of objects (as the name implies) and it looks like `host_address/api/entity`.
Detail endpoints return a single instance of an object and it looks similar to the list endpoint, except for the fact that it expects a path param, the ID of the object, to identify the instance that will be returned (e.g. `/api/entity/[id]`).
Custom endpoints are routes made by developers to solve any use-cases different from the default ones. They don't have a specific format, offering devs more freedom.
1
12 reads
Each endpoint needs a function to manipulate and return the data. But these functions have a standard format
1
13 reads
Now let's focus on what's the steps for a request to be fulfilled on a Tastypie endpoint.
When a request is received from a client, Django checks for any existing routes inside `urlpatterns`, the variable with all the available routes inside the project.
If a pattern was found, Django will call the associated view (function or class) with the following parameters:
If the URL didn't match any pattern, then Django will take care of it via an appropriate error handling view.
1
6 reads
Once Django redirects the request to a Tastypie resource, it checks for the available URLs and lets Tastypie do the rest.
Assuming the URL is`host-domain/api/v1/entity/` (which is a list view):
If the view was matched, `Resource.wrap_view('dispatch_list')` is called. The wrap_view method inside the Resource takes care of basic error handling and serialisation for the errors. The 'dispatch_list' parameter means that Resource.dispatch_list will be called next (a thin wrapper around the dispatch method).
1
8 reads
The dispatch method makes sure the followings are fulfilled:
1
11 reads
The response is generated using the specific class method of the resource. If it's a default endpoint, the methods look like [HTTP_method]_[view_type] (e.g. get_list, post_detail) and if it's a custom endpoint, the method's name is the defined route for the endpoint (e.g. add_more_entries)
1
12 reads
The following actions will be done when calling the get_list:
Observation: For POST/PUT, there will be an extra step, the hydrate cycle, that will take the request payload and convert it in raw data, for DB storage
1
11 reads
IDEAS CURATED BY
CURATOR'S NOTE
My takes after reading the Tastypie documentation, regarding how a request is handled inside an endpoint
“
Learn more about computerscience with this collection
Understanding machine learning models
Improving data analysis and decision-making
How Google uses logic in machine learning
Related collections
Similar ideas
1 idea
Foreign Key on Models | Django documentation
docs.djangoproject.com
6 ideas
Save vs Update in Django
helmut.dev
11 ideas
Read & Learn
20x Faster
without
deepstash
with
deepstash
with
deepstash
Personalized microlearning
—
100+ Learning Journeys
—
Access to 200,000+ ideas
—
Access to the mobile app
—
Unlimited idea saving
—
—
Unlimited history
—
—
Unlimited listening to ideas
—
—
Downloading & offline access
—
—
Supercharge your mind with one idea per day
Enter your email and spend 1 minute every day to learn something new.
I agree to receive email updates