Skip to content

yosniersm/wordplease-2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wordplease

To the teacher

  1. Thanks for your classes.
  2. Optional tasks can be found in development branch.

API usage

Note: Some endpoints require authentication.

How to register an user

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"
}

How to get user Token

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"
}

Getting available blogs

http://localhost:8000/api/1.0/blogs/

Getting posts from user blog

http://localhost:8000/api/1.0/blogs/<username>

How to search for a post within a blog

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:

Note: Body or title query_params will have priority over search query_param.

How to order the posts

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

How to create a post

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/

How to retreive post detail

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>

How to update post detail

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]
}

How to delete a post

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:

DELETE http://localhost:8000/api/1.0/posts/<id>

About

Wordpresslike platform using Python and Django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 84.1%
  • Python 13.4%
  • HTML 2.5%