This is a sample API for experimenting with the JSON:API format. It allows you to create an account so you can modify your own data.

Sign up for a free account. Then you can use the same username and password to log in to the API.

Contents

Logging In

You authenticate to the API with the OAuth 2 password grant.

POST https://sandboxapi.reststate.org/oauth/token

grant_type=password
username=you@yourodmain.com
password=yourpassword

You'll receive back the token to use:

{
    "access_token": "b027b3ed38739a1d01c2ac05008f0cb4e7a764acc802e0cfb1e5bf1a4876597c",
    "token_type": "bearer",
    "expires_in": 7200,
    "created_at": 1531855327
}

Accessing Data

All your requests should include the following headers:
Content-Type=application/vnd.api+json
Authorization=Bearer YOUR_TOKEN

List Posts

GET https://sandboxapi.reststate.org/posts
Response:
200 OK
{
    "data": [
        {
            "id": "1",
            "type": "posts",
            "links": {
                "self": "https://sandboxapi.reststate.org/posts/1"
            },
            "attributes": {
                "title": "Test Post",
                "body": "This is a test!"
            }
        }
    ]
}

Show Post

GET https://sandboxapi.reststate.org/posts/1
Response:
200 OK
{
    "data": {
        "id": "1",
        "type": "posts",
        "links": {
            "self": "https://sandboxapi.reststate.org/posts/1"
        },
        "attributes": {
            "title": "Test Post",
            "body": "This is a test!"
        }
    }
}

Create Post

Request
POST https://sandboxapi.reststate.org/posts
{
    "data": {
        "type": "posts",
        "attributes": {
            "title": "Posted Post",
            "body": "This post is posted!"
        }
    }
}
Response
201 Created
{
    "data": {
        "id": "2",
        "type": "posts",
        "links": {
            "self": "https://sandboxapi.reststate.org/posts/2"
        },
        "attributes": {
            "title": "Posted Post",
            "body": "This post is posted!"
        }
    }
}

Update Post

Request
PATCH https://sandboxapi.reststate.org/posts/1
{
    "data": {
        "id": "1",
        "type": "posts",
        "attributes": {
            "title": "Updated Post"
        }
    }
}
Response
200 OK
{
    "data": {
        "id": "1",
        "type": "posts",
        "links": {
            "self": "https://sandboxapi.reststate.org/posts/1"
        },
        "attributes": {
            "title": "Updated Post",
            "body": "This is a test!"
        }
    }
}

Delete Post

Request
DELETE https://sandboxapi.reststate.org/posts/1
Response
204 No Content

Learning More

About Sandbox API

This API is implemented with Ruby on Rails and the jsonapi_resources gem. It's one of the easiest ways to create an API! For help creating a pre-configured project, use my Rails API Template.

View the GitHub repo for Sandbox API to download and run it locally, or to contribute.

Other gems used:

Sandbox API is by CodingItWrong