Skip to content

API Documentation

Chris Read edited this page Dec 2, 2020 · 13 revisions

The Goodlaughs API is organized around REST. Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes and verbs.

API routes are not user-facing and should only be used by developers.

Resources:


Reviews

Endpoints for the Reviews resource:


Get All Reviews

Returns all reviews

GET /api/reviews

fetch(/api/reviews)

Query Parameters

Parameter Type Description Notes
limit number limit of how many reviews can be retrieved at one time optional, default of 20, max of 100
cursor number a cursor for use in pagination, starting point of the list returned optional

Returns

Returns an array of review objects if successful, and returns an error otherwise


Get a Review

Retrieves a single review of the specified id

GET /api/reviews/:id

fetch(/api/reviews/:id)

Path Parameters

Parameter Type Description Notes
id ID id of the review to retrieve required

Returns

Returns a review object if successful, and returns an error otherwise.


Get All Reviews on a Single Laugh

Retrieves all reviews on a single laugh of the specified laugh id

GET /api/laughs/:id/reviews

fetch(/api/laughs/:id/reviews)

Path Parameters

Parameter Type Description Notes
id ID id of the laugh required

Returns

Returns an array of review objects if successful, and returns an error otherwise.


Review a Laugh

Creates a review between the current user on the specified laugh id
requires authentication with a cookie

POST /api/laughs/:id/reviews

fetch(/api/laughs/:id/reviews)

Path Parameters

Parameter Type Description Notes
id ID id of the laugh to review required

Returns

Returns a review object if successful, and returns an error otherwise.


Update a Review

Updates a review by the current user on the specified review
requires authentication with a cookie

PUT /api/laughs/:id/reviews

fetch(/api/laughs/:id/reviews)

Path Parameters

Parameter Type Description Notes
id ID id of the laugh to update required

Returns

Returns the review as a review object if successful, and returns an error otherwise.


Unreview a Laugh

Deletes a specified review by the current user on a specified laugh
requires authentication with a cookie

DELETE /api/laughs/:idLaugh/reviews/:idReview

fetch(/api/laughs/:idLaugh/reviews/:idReview)

Path Parameters

Parameter Type Description Notes
idLaugh ID id of the laugh to unreview required
idReview ID id of the review to unreview required

Returns

Returns a success message if successful, and returns an error otherwise.


Objects

Review Object

{
  "id": 41,
  "body": "Hello World! This is a funny joke.",
  "userId": 1,
  "laughId": 5,
  "createdAt": "2020-10-18T20:26:34.256Z",
  "updatedAt": "2020-10-18T20:26:34.256Z"
}

Clone this wiki locally