Skip to content

Latest commit

 

History

History
303 lines (207 loc) · 7.58 KB

resource-template.md

File metadata and controls

303 lines (207 loc) · 7.58 KB
layout title
default
Example Resource

Example Resource

Introductory paragraphs describing the resource.

Sections

{% include endpoints_and_url_structures.md %}

The link relation label for a Example Resource resource is osdi:example_resource for a single Example Resource resource or osdi:example_resources for a collection of Example Resource resources.

Back to top...

Fields

{% include fields_intro.md %}

{% include global_fields.md %}

Back to top...

Example Resource Fields

A list of fields specific to the Example Resource.

Name Type Description
field1 string field1 description
field2 ExampleObject An instance of an Example Object
field3 ExampleObject[] An array of Example Objects

Back to top...

Related Objects

These objects included in the table above are broken out into their own tables for readability, rather than independent resources with their own endpoints.

Example Object

Name Type Description
field1 string Description of field1
field2 string Description of field2

Back to top...

Links

{% include links_intro.md %}

Name Type Description
self Example Resource* A self-referential link to the resource.
linked_resource1 LinkedResourceType1* A link to the instance of LinkedResourceType1
linked_resource2 LinkedResourceType2[]* A link to the collection of resources

Back to top...

Helpers

{% include helpers_intro.md %}

Name Description
example_helper1 Description of helper's purpose.
example_helper2 Description of helper's purpose.

Back to top...

Related Resources

Back to top...

Scenarios

{% include scenarios_intro.md %}

Scenario: Retrieving a collection of resources (GET)

Resource Example resources are sometimes presented as collections of resource example. For example, calling the resource example endpoint will return a collection of all the resource example stored in the system's database associated with your api key.

Request

GET https://osdi-sample-system.org/api/v1/resource

Header:
OSDI-API-Token:[your api key here]

Response

200 OK

Content-Type: application/hal+json
Cache-Control: max-age=0, private, must-revalidate

{
    "total_pages": 88,
    "per_page": 25,
    "page": 1,
    "total_records": 2188,
    "_links": {
        "next": {
            "href": "https://osdi-sample-system.org/api/v1/resource?page=2"
        },
        "curies": [
            {
                "name": "osdi",
                "href": "https://osdi-sample-system.org/docs/v1/{rel}",
                "templated": true
            }
        ],
        "self": {
            "href": "https://osdi-sample-system.org/api/v1/resource"
        },
        //other links here
    },
    "_embedded": {
        "osdi:resource": [
            //fields go here
        ]
    }
}

Back to top...

Scenario: Scenario: Retrieving an individual resource (GET)

Calling an individual Resource Example resource will return the resource directly, along with all associated fields and appropriate links to additional information about the resource.

Request

GET https://osdi-sample-system.org/api/v1/resource/d32fcdd6-7366-466d-a3b8-7e0d87c3cd8b

Header:
OSDI-API-Token:[your api key here]

Response

200 OK

Content-Type: application/hal+json
Cache-Control: max-age=0, private, must-revalidate

{
    "identifiers": [
        "osdi_sample_system:d91b4b2e-ae0e-4cd3-9ed7-d0ec501b0bc3",
        "foreign_system:1"
    ],
    "created_date": "2014-03-20T21:04:31Z",
    "modified_date": "2014-03-20T21:04:31Z",
    //more fields here
    "_links": {
        "self": {
            "href": "https://osdi-sample-system.org/api/v1/resource/d91b4b2e-ae0e-4cd3-9ed7-d0ec501b0bc3"
        },
        //more links here
    }
}

Back to top...

Scenario: Creating a new resource (POST)

Posting to the resource collection endpoint will allow you to create a new resource. The response is the new resource that was created. While each implementing system will require different fields, any optional fields not included in a post operation should not be set at all by the receiving system, or should be set to default values.

Request

POST https://osdi-sample-system.org/api/v1/resource/

Header:
OSDI-API-Token:[your api key here]

{
    //fields here
}

Response

200 OK

Content-Type: application/hal+json
Cache-Control: max-age=0, private, must-revalidate

{
    "identifiers": [
        "osdi_sample_system:d91b4b2e-ae0e-4cd3-9ed7-de9uemdse",
        "foreign_system:1"
    ],
    "created_date": "2014-03-20T21:04:31Z",
    "modified_date": "2014-03-20T21:04:31Z",
    // more fields/links here
}

Back to top...

Scenario: Modifying a resource (PUT)

You can updating a resource by calling a PUT operation on that resource's endpoint. Your PUT should contain fields that you want to update. Missing fields will be ignored by the receiving system. Systems may also ignore PUT values, depending on whether fields you are trying to modify are read-only or not. You may set an attribute to nil by including the attribute using nil for value.

{% include array_warning.md %}

Request

PUT https://osdi-sample-system.org/api/v1/resource/d91b4b2e-ae0e-4cd3-9ed7-de9uemdse

Header:
OSDI-API-Token:[your api key here]

{
    // fields here
}

Response

200 OK

Content-Type: application/hal+json
Cache-Control: max-age=0, private, must-revalidate

{
    "identifiers": [
        "osdi_sample_system:d91b4b2e-ae0e-4cd3-9ed7-de9uemdse",
    ],
    // more fields/links here
}

Back to top...

Scenario: Deleting a resource (DELETE)

You may delete a resource by calling the DELETE command on the resource's endpoint.

Request

DELETE https://osdi-sample-system.org/api/v1/resource/d32fcdd6-7366-466d-a3b8-7e0d87c3cd8b

Header:
OSDI-API-Token:[your api key here]

Response

200 OK

Content-Type: application/hal+json
Cache-Control: max-age=0, private, must-revalidate

{
    "notice": "This resource was successfully deleted."
}

Back to top...