- Thanks for your classes.
- Optional tasks can be found in development branch.
Note: Some endpoints require authentication.
First register yourself in the application using the following route:
POST http://localhost:8000/api/1.0/users/
With some Body like:
{
"username": "pablito",
"email": "mail@mail.com",
"first_name": "Pablito",
"last_name": "Perez",
"password":"supersegura"
}
Note: The user need to be registered in the application
To get your token you need to do a POST request with the following body:
POST http://localhost:8000/api/1.0/users/get-token/
{
"username": "pablito",
"password":"supersegura"
}
http://localhost:8000/api/1.0/blogs/
http://localhost:8000/api/1.0/blogs/<username>
The following query_params are allowed:
- search: This will allow you to look in the title OR body fields of posts.
- title: This will allow you to look in the title field of posts.
- body: This will allow you to look in the body field of posts.
Examples:
- Look for posts in username's blog containing case insensitive "wanted_word" in title or in the body. http://localhost:8000/api/1.0/blogs/<username>?search=wanted_word
- Look for posts in username's blog containing case insensitive "wanted_word" in title. http://localhost:8000/api/1.0/blogs/<username>?title=wanted_word
- Look for posts in username's blog containing case insensitive "wanted_word" in body. http://localhost:8000/api/1.0/blogs/<username>?body=wanted_word
- Look for posts in username's blog containing case insensitive "wanted_word" in body and "wanted_word2" in title. http://localhost:8000/api/1.0/blogs/<username>?body=wanted_word&title=wanted_word2
Note: Body or title query_params will have priority over search query_param.
Simply add the query_param order_by. Possible values are:
- title, will return results in ascending order.
- publication_date, will return results in ascending order.
- -title, will return results in descending order.
- -publication_date, will return results in descending order.
Example: http://localhost:8000/api/1.0/blogs/<username>?order_by=title
You need to be authenticated to reach this endpoint.
You will need the following Headers on your POST request:
- Content-Type: application/json
- Authorization: Token 4f5dbe4c76decf3eb187aea636fa68efd3855ef9
Then, you will need to specify some Body in your request:
{
"title": "Your title",
"image": "https://source.unsplash.com/random",
"summary": "The summary",
"body": "The body",
"publication_date": "2014-12-10",
"category":[1,2]
}
Or
{
"title": "Your title",
"video": "https://source.unsplash.com/random",
"summary": "The summary",
"body": "The body",
"publication_date": "2014-12-10",
"category":[1,2]
}
Then you need to perform the request:
POST http://localhost:8000/api/1.0/posts/
If you are not authenticated you will see only published posts.
I you are authenticated and if you are a superuser or if you are the owner of the post you will see it even if the post is not published.
GET http://localhost:8000/api/1.0/posts/<id>
If you are not authenticated you cant update posts.
If you are authenticated and if you are a superuser or if you are the owner of the post can update the post.
To do the update do a PUT request with the Authorization Header and the corresponding body like the following example:
PUT http://localhost:8000/api/1.0/posts/<id>
{
"title": "Your title",
"image": "https://source.unsplash.com/random",
"summary": "The summary",
"body": "The body",
"publication_date": "2014-12-10",
"category":[1,2]
}
If you are not authenticated you cant delete posts.
If you are authenticated and if you are a superuser or if you are the owner of the post can delete the post.
To delete a post do a DELETE request with the Authorization Header like the following example: