Skip to content

RESTful API P1

annypanny edited this page Nov 29, 2016 · 30 revisions

/posts

  • It used to get the content of all the posts that public on our server.

  • It returned a JSON.

  • JSON file contains:

    • "count"
    • "posts"
    • "next"
    • "query"
    • "size"
    • "previous"

    and in each "posts", it has:

    • "id"
    • "published"
    • "title"
    • "description"
    • "contentType"
    • "content"
    • "source"
    • "origin"
    • "author"
    • "comments"
    • "visibility"
    • "image"

    and in each "comments", it has:

    • "author"
    • "comment"
    • "pubdate"
    • "id"
    • "contentType"
    • "post"

    and in each "author", it has:

    • "displayName"
    • "id"
    • "host"
    • "url"
    • "github"

Optional parameter:

  • ?page={integer}

    The page you want to see now and it's less than or equal to the total number of pages the server has.

    example url: http://127.0.0.1:8000/posts/?page=2 (shows page 2)

  • ?page={integer}&size={integer}

    The page you want to see now, and each page shows exactly the number of post you request in the size.

    example url: http://127.0.0.1:8000/posts/?page=2&size=5 (shows page 2, and each page has 5 posts)

Method:

GET

Example:

GET /posts


HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 2,
    "posts": [
	{
	    "id": "20d4a6fb-da69-4359-90a6-44497ae533cc",
	    "published": "2016-11-27T23:30:44.598751Z",
	    "title": "I love dogs",
	    "description": "Dogs are nice",
	    "contentType": "text/plain",
	    "content": "I like them",
	    "source": "http://socialnets404.herokuapp.com/posts/20d4a6fb-da69-4359-90a6-44497ae533cc/",
	    "origin": "http://socialnets404.herokuapp.com/posts/20d4a6fb-da69-4359-90a6-44497ae533cc/",
	    "author": {
	        "displayName": "Administrator",
	        "id": "c974a1fd-fa8c-4d99-97d6-6006e0ee0a5f",
	        "host": "http://socialnets404.herokuapp.com/",
	        "url": "http://socialnets404.herokuapp.com/author/c974a1fd-fa8c-4d99-97d6-6006e0ee0a5f",
	        "github": "jiafengwu0301"
	    },
	    "comments": [],
	    "visibility": "PUBLIC",
	    "image": ""
	},
	{
	    "id": "e0420969-e020-4bdb-8285-3ea5d0f97878",
	    "published": "2016-11-28T01:45:29.737511Z",
	    "title": "first post",
	    "description": "this is my first post",
	    "contentType": "text/x-markdown",
	    "content": "this is my first post",
	    "source": "http://socialnets404.herokuapp.com/posts/e0420969-e020-4bdb-8285-3ea5d0f97878",
	    "origin": "http://socialnets404.herokuapp.com/posts/e0420969-e020-4bdb-8285-3ea5d0f97878",
	    "author": {
	        "displayName": "iamuser",
	        "id": "d2325f9c-09de-492a-83a9-409047905e40",
	        "host": "http://socialnets404.herokuapp.com/",
	        "url": "http://socialnets404.herokuapp.com/author/d2325f9c-09de-492a-83a9-409047905e40",
	        "github": "[email protected]"
	    },
	    "comments": [
	        {
	            "author": {
	                "displayName": "Jiafeng Wu",
	                "id": "eb572e7b-7856-468b-bfdf-9b6388f9165c",
	                "host": "http://socialnets404.herokuapp.com/",
	                "url": "http://socialnets404.herokuapp.com/author/eb572e7b-7856-468b-bfdf-9b6388f9165c",
	                "github": "jiafengwu0301"
	            },
	            "comment": "blah blah blah",
	            "pubdate": "2016-11-28T21:21:32.476742Z",
	            "id": "a94416b4-c6bd-4dac-8fc2-fbf8886c9396",
	            "contentType": "text/plain",
	            "post": "http://socialnets404.herokuapp.com/posts/e0420969-e020-4bdb-8285-3ea5d0f97878"
	        }
	    ],
	    "visibility": "PUBLIC",
	    "image": ""
	}
    ],
    "next": null,
    "query": "posts",
    "size": 100,
    "previous": null
}

Clone this wiki locally