Skip to content

Latest commit

 

History

History
614 lines (547 loc) · 14 KB

Examples.md

File metadata and controls

614 lines (547 loc) · 14 KB

Resource Methods

POST /users

Add a new resource.

URL: http://localhost:10200/users

Request:

Accept: application/vnd.api+json
{
  "data": {
    "type": "users",
    "attributes": {
      "email": "[email protected]",
      "password": "ryan",
      "gender": "m"
    },
    "relationships": {
      "mom": {
        "data": {
          "type": "users",
          "id": "[email protected]"
        }
      }
    }
  }
}

Response:

201 CREATED
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 992 
Location: http://localhost:10200/v1/users/[email protected] 
Date: Tue, 15 Sep 2015 04:31:28 GMT 
{
  "data": {
    "attributes": {
      "active": true, 
      "created": "Sun, 27 Sep 2015 16:54:19 GMT", 
      "email": "[email protected]", 
      "gender": "m", 
      "id": "[email protected]", 
      "type": "users", 
      "updated": "Sun, 27 Sep 2015 16:54:19 GMT"
    }, 
    "id": "[email protected]", 
    "relationships": {
      "friends": {
        "data": [], 
        "links": {
          "related": "http://localhost:10200/v1/users/[email protected]/friends", 
          "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
        }
      }, 
      "mom": {
        "data": {
          "id": "[email protected]", 
          "type": "users"
        }, 
        "links": {
          "related": "http://localhost:10200/v1/users/[email protected]/mom", 
          "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
        }
      }
    }, 
    "type": "users"
  }, 
  "links": {
    "self": "http://localhost:10200/v1/users/[email protected]"
  }
} 

PATCH /users/< id >

Modify an existing resource.

URL: http://localhost:10200/users/[email protected]

Request:

Accept: application/vnd.api+json
{
  "data": {
    "type": "users",
    "attributes": {
      "password": "muchHarderPasswordToGuess"
    }
  }
}

Response:

200 OK
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 992 
Location: http://localhost:10200/v1/users/[email protected] 
Date: Tue, 15 Sep 2015 04:31:28 GMT 
{
  "data": {
    "attributes": {
      "active": true, 
      "created": "Sun, 27 Sep 2015 16:54:19 GMT", 
      "email": "[email protected]", 
      "gender": "m", 
      "id": "[email protected]", 
      "type": "users", 
      "updated": "Sun, 27 Sep 2015 17:18:38 GMT"
    }, 
    "id": "[email protected]", 
    "relationships": {
      "friends": {
        "data": [], 
        "links": {
          "related": "http://localhost:10200/v1/users/[email protected]/friends", 
          "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
        }
      }, 
      "mom": {
        "data": {
          "id": "[email protected]", 
          "type": "users"
        }, 
        "links": {
          "related": "http://localhost:10200/v1/users/[email protected]/mom", 
          "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
        }
      }
    }, 
    "type": "users"
  }, 
  "links": {
    "self": "http://localhost:10200/v1/users/[email protected]"
  }
} 

DELETE /users/< id >

Deactivate an existing resource.

URL: http://localhost:10200/users/[email protected]

Request:

Accept: application/vnd.api+json

Response:

204 NO CONTENT
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 0
Date: Tue, 15 Sep 2015 04:31:28 GMT 

GET /users/<id>

Fetch an existing resource.

URL: http://localhost:10200/users/[email protected]?include=mom*

*More info on the include parameter can be found here

Request:

Accept: application/vnd.api+json

Response:

200 OK
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 1050
Date: Tue, 15 Sep 2015 04:31:28 GMT 
{
  "data": {
    "attributes": {
      "active": true, 
      "created": "Sun, 27 Sep 2015 16:54:19 GMT", 
      "email": "[email protected]", 
      "gender": "m", 
      "id": "[email protected]", 
      "type": "users", 
      "updated": "Sun, 27 Sep 2015 17:18:38 GMT"
    }, 
    "id": "[email protected]", 
    "relationships": {
      "friends": {
        "data": [], 
        "links": {
          "related": "http://localhost:10200/v1/users/[email protected]/friends", 
          "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
        }
      }, 
      "mom": {
        "data": {
          "id": "[email protected]", 
          "type": "users"
        }, 
        "links": {
          "related": "http://localhost:10200/v1/users/[email protected]/mom", 
          "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
        }
      }
    }, 
    "type": "users"
  }, 
  "included": [
    {
      "attributes": {
        "active": true, 
        "created": "Sun, 27 Sep 2015 16:54:19 GMT", 
        "email": "[email protected]", 
        "gender": "f", 
        "id": "[email protected]", 
        "type": "users", 
        "updated": "Sun, 27 Sep 2015 16:54:19 GMT"
      }, 
      "id": "[email protected]", 
      "relationships": {
        "friends": {
          "data": [], 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/friends", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
          }
        }, 
        "mom": {
          "data": null, 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/mom", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
          }
        }
      }, 
      "type": "users"
    }
  ], 
  "links": {
    "self": "http://localhost:10200/v1/users/[email protected]"
  }
}

GET /users

Fetch a resource collection

URL: http://localhost:10200/users?page[offset]=0&page[limit]=1*

*More info on pagination can be found here

Request:

Accept: application/vnd.api+json

Response:

200 OK
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 1061
Date: Tue, 15 Sep 2015 04:31:28 GMT 
{
  "data": [
    {
      "attributes": {
        "active": true, 
        "created": "Sun, 27 Sep 2015 16:54:19 GMT", 
        "email": "[email protected]", 
        "gender": "m", 
        "id": "[email protected]", 
        "type": "users", 
        "updated": "Sun, 27 Sep 2015 16:54:19 GMT"
      }, 
      "id": "[email protected]", 
      "relationships": {
        "friends": {
          "data": [], 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/friends", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
          }
        }, 
        "mom": {
          "data": null, 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/mom", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
          }
        }
      }, 
      "type": "users"
    }
  ], 
  "links": {
    "first": "http://localhost:10200/v1/users?page[offset]=0&page[limit]=1", 
    "last": "http://localhost:10200/v1/users?page[offset]=2&page[limit]=1", 
    "next": "http://localhost:10200/v1/users?page[offset]=1&page[limit]=1", 
    "self": "http://localhost:10200/v1/users?page[offset]=0&page[limit]=1"
  }
}

Relationship Methods

POST /users/<id>/relationships/friends*

Add an item to a relationship collection.

*Note: use POST for collections with MANY items, otherwise use PATCH

URL: http://localhost:10200/users/[email protected]/relationships/friends

Request:

Accept: application/vnd.api+json
{
  "data": [
    {
      "type": "users",
      "id": "[email protected]",
      "meta": {
        "met": "space camp"
      }
    }
  ]
}

Response:

204 NO CONTENT
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 0
Date: Tue, 15 Sep 2015 04:31:28 GMT 

PATCH /users/<id>/relationships/mom

This method does a total replace on a relationship. It should therefore be used to create relationships with cardinality <= 1. It can also be used to delete all relationships.

URL: http://localhost:10200/v1/users/[email protected]/relationships/mom

Request to create:

Accept: application/vnd.api+json
{
"data":{"type":"users", "id":"[email protected]"}
}

Request to delete:

Accept: application/vnd.api+json
{
"data":null
}

Response:

204 NO CONTENT
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 0
Date: Tue, 15 Sep 2015 04:31:28 GMT 

DELETE /users/<id>/relationships/friends

Use this method to delete certain relationships contained in the body. Only the relationships in the body will be deleted. This method is only for collections with cardinality > 1.

URL: http://localhost:10200/v1/users/[email protected]/relationships/friends

Request:

Accept: application/vnd.api+json
{
  "data": [
    {
      "type": "users",
      "id": "[email protected]"
    }
  ]
}

Response:

204 NO CONTENT
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 0
Date: Tue, 15 Sep 2015 04:31:28 GMT

PATCH /users/<id>/relationships/friends

On collections with cardinality > 1 use this method to delete all existing items in that collection.

URL: http://localhost:10200/v1/users/[email protected]/relationships/friends

Request:

Accept: application/vnd.api+json
{
"data": []
}

Response:

204 NO CONTENT
Content-Type: application/vnd.api+json; charset=utf-8 
Content-Length: 0
Date: Tue, 15 Sep 2015 04:31:28 GMT

GET /users/<id>/relationships/friends

Fetch a relationship.

URL: http://localhost:10200/v1/users/[email protected]/relationships/friends

Request:

Accept: application/vnd.api+json
{
  "data": [
    {
      "id": "[email protected]", 
      "meta": {
        "created": "Sun, 27 Sep 2015 18:16:47 GMT", 
        "met": "space camp", 
        "type": "friend", 
        "updated": "Sun, 27 Sep 2015 18:16:47 GMT"
      }, 
      "type": "users"
    }, 
    {
      "id": "[email protected]", 
      "meta": {
        "created": "Sun, 27 Sep 2015 18:16:47 GMT", 
        "met": "taco tuesday party", 
        "type": "friend", 
        "updated": "Sun, 27 Sep 2015 18:16:47 GMT"
      }, 
      "type": "users"
    }, 
    {
      "id": "[email protected]", 
      "meta": {
        "created": "Sun, 27 Sep 2015 18:16:47 GMT", 
        "met": "at atheist revival", 
        "type": "friend", 
        "updated": "Sun, 27 Sep 2015 18:16:47 GMT"
      }, 
      "type": "users"
    }
  ], 
  "included": [
    {
      "attributes": {
        "active": true, 
        "created": "Sun, 27 Sep 2015 18:16:47 GMT", 
        "email": "[email protected]", 
        "gender": "m", 
        "id": "[email protected]", 
        "type": "users", 
        "updated": "Sun, 27 Sep 2015 18:16:47 GMT"
      }, 
      "id": "[email protected]", 
      "relationships": {
        "friends": {
          "data": [
            {
              "id": "[email protected]", 
              "type": "users"
            }
          ], 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/friends", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
          }
        }, 
        "mom": {
          "data": null, 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/mom", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
          }
        }
      }, 
      "type": "users"
    }, 
    {
      "attributes": {
        "active": true, 
        "created": "Sun, 27 Sep 2015 18:16:47 GMT", 
        "email": "[email protected]", 
        "gender": "m", 
        "id": "[email protected]", 
        "type": "users", 
        "updated": "Sun, 27 Sep 2015 18:16:47 GMT"
      }, 
      "id": "[email protected]", 
      "relationships": {
        "friends": {
          "data": [
            {
              "id": "[email protected]", 
              "type": "users"
            }
          ], 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/friends", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
          }
        }, 
        "mom": {
          "data": null, 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/mom", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
          }
        }
      }, 
      "type": "users"
    }, 
    {
      "attributes": {
        "active": true, 
        "created": "Sun, 27 Sep 2015 16:54:19 GMT", 
        "email": "[email protected]", 
        "gender": "m", 
        "id": "[email protected]", 
        "type": "users", 
        "updated": "Sun, 27 Sep 2015 17:18:38 GMT"
      }, 
      "id": "[email protected]", 
      "relationships": {
        "friends": {
          "data": [
            {
              "id": "[email protected]", 
              "type": "users"
            }
          ], 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/friends", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends"
          }
        }, 
        "mom": {
          "data": null, 
          "links": {
            "related": "http://localhost:10200/v1/users/[email protected]/mom", 
            "self": "http://localhost:10200/v1/users/[email protected]/relationships/mom"
          }
        }
      }, 
      "type": "users"
    }
  ], 
  "links": {
    "first": "http://localhost:10200/v1/users/[email protected]/relationships/friends?page[offset]=0&page[limit]=20", 
    "last": "http://localhost:10200/v1/users/[email protected]/relationships/friends?page[offset]=0&page[limit]=20", 
    "related": "http://localhost:10200/v1/users/[email protected]/friends", 
    "self": "http://localhost:10200/v1/users/[email protected]/relationships/friends?page[offset]=0&page[limit]=20"
  }
}