Skip to content

Instantly share code, notes, and snippets.

@MelTravelz
Forked from hamouj/json_contract.md
Last active October 13, 2023 16:30
Show Gist options
  • Save MelTravelz/711af74cef605727245590b916820d9d to your computer and use it in GitHub Desktop.
Save MelTravelz/711af74cef605727245590b916820d9d to your computer and use it in GitHub Desktop.
BE - Do Good Endpoints

Do Good JSON Contract


Request: GET "/api/v1/good_deeds"

Response:

{
  "data": [{
    "id": “1”,
    "type": “good_deed",
    "attributes":{
        "name": "High-five a stranger.",
        "media_link": "http://neverland.io/mermaids"
     }  
   }]
}

Request: GET "/api/v1/random_acts"

Response:

{
  "data": {
    "id": “1”,
    "type": “random_acts",
    "attributes":{ 
        "deed_names": ["Deed 1", "Deed 2", "Deed 3"] 
     }  
   }
}

Request: GET "/api/v1/users

Response:

{
  "data": [{
    "id": “1”,
    "type": “users",
    "attributes":{ 
      "name": "Tink", 
      "role": "user",
      "good_deeds": []
    }},
    {
    "id": “2”,
    "type": “users",
    "attributes":{ 
      "name": "Peter Pan", 
      "role": "user",
      "good_deeds": []
    }}
   ]
}

Request: POST "/api/v1/users/:id/good_deeds

Body of Request:

{
  "name": "High-five a stranger.",
  “date”: "02-02-2024",
  "time": "2000-01-01T16:00:00.000Z",
  "attendees": [1, 2, 3],
  "host_name": "Tink"
 }

Response:

{:data=> {
   :id=>"1",
   :type=>"good_deeds_create",
   :attributes=> {
     :name=>"High-five a stranger.",
     :media_link=>nil,
     :notes=>nil,
     :date=>"2023-01-01",
     :time=>"2000-01-01T17:00:00.000Z",
     :status=>"In Progress",
     :host_id=>1026
     }
   }
}

Request: GET "/api/v1/users/:id"

Response:

{
  "data": {
      "id": “1”,
      "type": “user",
      "attributes":{
          "name": "Tink",
          "role": "user",
          "good_deeds": {
              "data": [{
                  "id": “1”,
                  "type": “good_deed",
                  "attributes":{
                      "name": "High-five a stranger.",
                      "host_id": "9000",
                      "host_name": "Shmee",
                      “date”: "02-02-2024",
                      "time": "2000-01-01T16:00:00.000Z",
                      "status": "Completed", 
                      "media_link": "http://neverland.io/mermaids",
                      "notes”: "OMG, can't believe we high-fived mermaids today!",
                      "attendees": [{"name": "Peter"}, {"name": "Hook"}]
                   }
                }]
           }
        }
  }
}

Request: GET "/api/v1/users/:id/good_deeds/:id"

Response:

{
  "data": {
      "id": "1",
      "type": "good_deed",
      "attributes": {
          "name": "High-five a stranger.",
          "date": "2023-07-04",
          "time": "2000-01-01T16:00:00.000Z",
          "status": "In Progress",
          "media_link": "http://neverland.io/mermaids",
          "notes": "OMG, can't believe we high-fived mermaids today!", 
          "attendees": [{"user_id": 2, "name": "Peter"}, {"user_id": 3, "name": "Hook"}]
       }
   }
}

Request: PATCH "/api/v1/users/:id/good_deeds/:id"

Body of Request:

{
  "date": "02-02-2024",
  "time": "2000-01-01T16:00:00.000Z",
  "status": "Completed",
  "media_link": "http://neverland.io/mermaids",
  "notes": "OMG, can't believe we high-fived mermaids today!",
  "attendees": [{"user_id": 1}, {"user_id": 2}]
 }

Response:

{
   "data": {
       "id": "1",
       "type": "good_deed",
       "attributes": {
           "name": "High-five a stranger.",
           "date": "2024-02-02",
           "time": "2000-01-01T16:00:00.000Z",
           "status": "Completed",
           "notes": "OMG, can't believe we high-fived mermaids today!",
           "media_link": "http://neverland.io/mermaids",
           "host_id": 2,
           "host_name": "Tink",
           "attendees": []
       }
   }
}

Request: DELETE "/api/v1/users/:id/good_deeds/:id"


Request: POST “/api/v1/users”

Body of Request:

{"query":
   {"provider": "google_oauth2", 
    "uid": "100000000000000000000", 
    "info": {"name": "Peter Pan", 
             "email": "the_pan@neverland.com", 
             "first_name": "Peter", 
             "last_name": "Pan", 
             "image": "https://lh4.googleusercontent.com/photo.jpg", 
             "urls": {"google": "https://plus.google.com/+PeterPan"}
             }
     }
}

Response:

{
    "data": [
        {
            "id": "2",
            "type": "users",
            "attributes": {
                "name": "Peter Pan",
                "role": "user",
                "email": "the_pan@neverland.com",
                "good_deeds": {
                    "data": [
                        {
                            "id": "9",
                            "type": "good_deed",
                            "attributes": {
                                "name": "High-five a stranger.",
                                "date": "2024-02-02",
                                "time": "2000-01-01T16:00:00.000Z",
                                "status": "In Progress",
                                "notes": null,
                                "media_link": null,
                                "host_id": 1,
                                "host_name": "Peter Pan",
                                "attendees": []
                            }
                        }]
                 }
          }
     }]
}

Error Object:

{
  "errors": [{
      "status": "404",
      "title": "Invalid Request",
      "detail": ["Couldn't find User with 'id'=<id>"]
   }]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment