Create
There are two ways to create a resource, either with an HTTP POST or with an HTTP PUT.
To create a resource using POST, perform an HTTP POST with the query string parameter _action=create
and the JSON resource as a payload. The server creates the identifier if not specified:
POST /users?_action=create HTTP/1.1
Host: example.com
Accept: application/json
Content-Length: ...
Content-Type: application/json
{ JSON resource }
To create a resource using PUT, perform an HTTP PUT including the case-sensitive identifier for the resource in the URL path, and the JSON resource as a payload. Optionally, include the If-None-Match: *
header to prevent overwriting an existing object:
PUT /users/some-id HTTP/1.1
Host: example.com
Accept: application/json
Content-Length: ...
Content-Type: application/json
If-None-Match: *
{ JSON resource }
The _id
and content of the resource depend on the server implementation. The server is not required to use the _id
that the client provides. The server response to the create request indicates the resource location as the value of the Location
header.
If you include the If-None-Match
header, its value must be *
. In this case, the request creates the object if it does not exist, and fails if the object does exist. If you include the If-None-Match
header with any value other than *
, the server returns an HTTP 400 Bad Request error. For example, creating an object with If-None-Match: revision
returns a bad request error. If you do not include If-None-Match: *
, the request creates the object if it does not exist, and updates the object if it does exist.
You can use the following parameters:
_prettyPrint=true
-
Format the body of the response.
_fields=field[,field...]
-
Return only the specified fields in the body of the response.
The
field
values are JSON pointers. For example if the resource is{"parent":{"child":"value"}}
,parent/child
refers to the"child":"value"
.If the
field
is left blank, the server returns all default values.