Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Latest commit

 

History

History
146 lines (106 loc) · 2.12 KB

COMMENTS.md

File metadata and controls

146 lines (106 loc) · 2.12 KB

Comments

Fetch all comments from database.

  • URL

    /comments

  • Method:

    GET

  • URL Params

    Required:

    none

    Optional:

    id=[integer] - movie id

  • Data Params

    none

  • Success Response:

    • Code: 200
      Content:
        [{
          "id": 1,
          "movie_id": 1,
          "comment": "comment1",
          "createdAt": "1999-01-08T00:00:00.000Z",
          "updatedAt": "1999-01-08T00:00:00.000Z"
        }, {
          "id": 2,
          "movie_id": 2,
          "comment": "comment2",
          "createdAt": "1999-01-08T00:00:00.000Z",
          "updatedAt": "1999-01-08T00:00:00.000Z"
        }]
  • Error Response:

    • Code: 500 Internal Server Error
      Content: { error: 'Something went wrong' }
  • Sample Call:

      $.ajax({
        url: "/comments?id=2",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
  • Notes:

    none


Add comment.

  • URL

    /comments

  • Method:

    POST

  • URL Params

    none

  • Data Params

    Required:

    Headers:

    { "Content-Type": "application/json" }

    Body:

    { 
      "ID": 1,
      "comment": "comment1"
    }

    Optional:

    none

  • Success Response:

    • Code: 200
      Content:
      {
        "id": 1,
        "movie_id": 1,
        "comment": "comment1",
        "createdAt": "2019-04-09T22:46:05.752Z",
        "updatedAt": "2019-04-09T22:46:05.752Z"
      }
  • Error Response:

    • Code: 500 Internal Server Error
      Content: { error: 'Something went wrong' }

    • Code: 400 Bad Request
      Content: { error: 'Movie id doesn't exists' }

  • Sample Call:

      $.ajax({
        url: "/comments",
        dataType: "json",
        contentType: 'application/json',
        type : "POST",
        data: {
          "ID": 1,
          "comment": "comment1"
        },
        success : function(r) {
          console.log(r);
        }
      });
  • Notes:

    none