© 2015 X2Engine Inc.
Difference between revisions of "REST API Reference"
Line 8: | Line 8: | ||
For example, to create a contact, one would send a <tt>POST</tt> request with its body a JSON-encoded attributes list to the URI | For example, to create a contact, one would send a <tt>POST</tt> request with its body a JSON-encoded attributes list to the URI | ||
index.php/api2/Contacts | index.php/api2/Contacts | ||
− | with the <tt>Content-Type</tt> header set to <tt> | + | with the <tt>Content-Type</tt> header set to <tt>application/json</tt>, and the body: |
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
{"firstName":"John","lastName":"Smith","visibility":1,"email":"johnsmith@example.com"} | {"firstName":"John","lastName":"Smith","visibility":1,"email":"johnsmith@example.com"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
If creation of the contact is successful, the server should respond with status code 201, and the response should contain a <tt>Location</tt> header with the full URL (including protocol) of the newly created contact (in addition to all the attributes of the new contact). If for example the new contact's ID is 123, that URI would be <tt>index.php/api2/Contacts/123.json</tt>, and a GET request to that URI would elicit a response from the server whose body contains a JSON-encoded list of attributes. | If creation of the contact is successful, the server should respond with status code 201, and the response should contain a <tt>Location</tt> header with the full URL (including protocol) of the newly created contact (in addition to all the attributes of the new contact). If for example the new contact's ID is 123, that URI would be <tt>index.php/api2/Contacts/123.json</tt>, and a GET request to that URI would elicit a response from the server whose body contains a JSON-encoded list of attributes. |
Revision as of 01:10, 2 May 2014
Introduction
This API within X2Engine, which can be accessed via the URI
index.php/api2
exclusively uses JSON for data input and output, and tends to use similar URIs for both input and output.
For example, to create a contact, one would send a POST request with its body a JSON-encoded attributes list to the URI
index.php/api2/Contacts
with the Content-Type header set to application/json, and the body:
{"firstName":"John","lastName":"Smith","visibility":1,"email":"johnsmith@example.com"}
If creation of the contact is successful, the server should respond with status code 201, and the response should contain a Location header with the full URL (including protocol) of the newly created contact (in addition to all the attributes of the new contact). If for example the new contact's ID is 123, that URI would be index.php/api2/Contacts/123.json, and a GET request to that URI would elicit a response from the server whose body contains a JSON-encoded list of attributes.