Amazon API Gateway REST API Reference

resource:create

Creates an API resource.

HTTP Request

POST /restapis/<restapi_id>/resources/<parent_id>

Request Body

{
  "pathPart" : "String"
}

Request Body Fields

The request accepts the following fields in JSON format.

  • pathPart
  • The last path segment for this resource.

Response

Resource

Remarks

To create a child resource under an API's root resource, make this POST request with the root resource identifier specified as the in the request URL.

Example: Create a child resource under an API's root resource

Request

The following example request creates a child resource under an API's root resource. The root resource identifer can be obtained from the response of a GET request on the API's Resources resource.

POST /restapis/fugvjdxtri/resources/3kzxbg5sa2 HTTP/1.1
Content-Type: application/json
Host: apigateway.us-east-1.amazonaws.com
X-Amz-Date: 20170223T010429Z
Authorization: AWS4-HMAC-SHA256 Credential={access_key_ID}/20170223/us-east-1/apigateway/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature={sig4_hash}

{
    "pathPart" : "res1"
}

The pathPart value is defined relative to the specified parent and cannot have the "/" character.

Response

The successful response returns 201 Created status and a payload similar to the following:

{
  "_links": {
    "curies": [
      {
        "href": "http://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-method-{rel}.html&quot;,
        "name": "method",
        "templated": true
      },
      {
        "href": "http://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-resource-{rel}.html&quot;,
        "name": "resource",
        "templated": true
      }
    ],
    "self": {
      "href": "/restapis/fugvjdxtri/resources/47rxl6"
    },
    "method:by-http-method": {
      "href": "/restapis/fugvjdxtri/resources/47rxl6/methods/{http_method}",
      "templated": true
    },
    "method:put": {
      "href": "/restapis/fugvjdxtri/resources/47rxl6/methods/{http_method}",
      "templated": true
    },
    "resource:create-child": {
      "href": "/restapis/fugvjdxtri/resources/47rxl6"
    },
    "resource:delete": {
      "href": "/restapis/fugvjdxtri/resources/47rxl6"
    },
    "resource:update": {
      "href": "/restapis/fugvjdxtri/resources/47rxl6"
    }
  },
  "id": "47rxl6",
  "parentId": "3kzxbg5sa2",
  "path": "/res1",
  "pathPart": "res1"
}

To continue creating a child resource (e.g., "/res1.1") under the newly created resource ("/res1"), repeat the same POST request, replacing the value with the res1 resource identifier (47rxl6) in the request URL and replacing the pathPart value with "res1.1". The path of the resulting child resource will be "/res1/res1.1".

See Also

Creating an API, AWS CLI