Frequently Asked Questions
When should I define a Resource vs. a Model?
A Model is a representation of what our application deals with internally. Whenever two parts of our application communicate with one another, they'll do so mainly by using Models.
However a Resource is a definition of how users interact with our application, so we define Resources to deal with user requests. Resources will use Models to communicate with other parts of the application and to interact with the database.
What is JSON?
JSON stands for JavaScript Object Notation. JavaScript objects are very similar to Python dictionaries in many ways, so when we look at JSON we're often looking at something that looks like a Python dictionary. For example:
{
"name": "Bob",
"username": "bob35",
"password": "1234"
}
Something to remember though, is that JSON is actually a single string–which contains all the other strings. This means that we can pass JSON in our requests and responses.
Because of its structure, we can then parse it and turn it into a Python dictionary very easily.
More reading material:
What are some common HTTP status codes?
The most common HTTP status code is not 404, as many people think! It is in fact 200, which means "OK".
Some others are:
200 OK
201 CREATED
301 PERMANENT REDIRECT
400 BAD REQUEST
401 UNAUTHORIZED
404 NOT FOUND
500 INTERNAL SERVER ERROR
There's many more HTTP status codes, and APIs should respond with the most reasonable status codes for what the API has done or has responded with. It's therefore important to keep an eye on status codes and make sure you're using the most correct one!
What HTTP methods are there?
The most popular HTTP methods are:
GET
POST
PUT
DELETE
OPTIONS
PATCH
There's a few more though, and while they have more niche use cases, they can be useful sometimes!
Any more questions?
If you think something else should be added to this section, let us know!