Skip to content

ashkush21/RESTful-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Api endpoint base URL: https://mockserver-commerceiq.herokuapp.com

About the project

  • RESTful api that stores and retrieves data from a .json file.
  • The structure of the object stored in file:
{
  "posts": [
    {
      "id": "0",
      "title": "title1",
      "author": "CIQ",
      "views": "100",
      "reviews": "31"
    },
    {
      "id": "1",
      "title": "title2",
      "author": "CommerceIQ",
      "views": "10",
      "reviews": "3"
    },
    {
      "id": "2",
      "title": "title3",
      "author": "myname",
      "views": "500",
      "reviews": "60"
    }
  ],
  "authors": [
    {
      "id": "0",
      "first_name": "commerce",
      "last_name": "IQ",
      "posts": "45"
    }
  ]
}
  • Here each key is referred to as "entity" in the api.
  • More keys, i.e. entities, can be inserted into the file using POST request.

Usage information for different request methods:

Append the endpoint after the base URL.

GET:

  • Endpoint: "/alldata"
    • This will return all the data in the .json file data store.
  • Endpoint: "/:entity"
  • Endpoint: "/:entity/:id"
  • Query parameters:
    • "/posts?title=titleValue&author=authorValue"
      • Replace "titlevalue" with any title of post and "authorValue" with any author name to search filter out the posts which contain that value
    • "/posts?_sort=sortAttribute&_order=orderOfSorting"
      • Replace "sortAttributes" with corresponding key to sort according to it's values and "orderOfSorting" with "asc" or "desc" for ascending and descending order of sorting.

POST:

  • Endpoint: "/:entity"
    • Pass the object to be inserted into the data store in the body of the request.
    • Replace entity with the dataset in which you want to add the object.
    • Example: (If using axios to make the request)
    axios.post("https://mockserver-commerceiq.herokuapp.com/posts", {
      id: "3",
      title: "title4",
      author: "somename",
      views: "500",
      reviews: "60",
    });

PUT:

  • Endpoint: "/:entity/:id"
    • Replace ":id" with the id of object which you want to replace and ":entity" with the corresponding dataset to which the object belongs.
    • Pass the object in request body to replace the object present in the datastore
    • Example: (If using axios to make the request)
    axios.put("https://mockserver-commerceiq.herokuapp.com/posts/1", {
      id: "5",
      title: "newtitle",
      author: "somename",
      views: "500",
      reviews: "60",
    });

PATCH:

  • Endpoint: "/:entity/:id"
    • Similar to POST request, except pass only those key-value pairs in the object which you need to change.
    • Example: Suppose you want to change "author" and "views" of the post with id=1,
    axios.patch("https://mockserver-commerceiq.herokuapp.com/posts/1", {
      author: "somename",
      views: "500",
    });

DELETE:

  • Endpoint: "/:entity/:id"
    • To delete and object pass the corresponding ":entity" and ":id".
    • Example: To delete post with id=2
	 axios.delete(
	 "https://mockserver-commerceiq.herokuapp.com/posts/2"
	 )
	 ```

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published