| description | You can test operations in the REST API by using command line, PHP or JS code. |
|---|
A standard web browser isn't sufficient to fully test the API.
You can, however, try opening the root resource with it, using the session authentication: http://example.com/api/ibexa/v2/.
Depending on how your browser understands XML, it either downloads the XML file, or opens it in the browser.
The following examples show how to interrogate the REST API with cURL, PHP or JS.
For examples of using curl, refer to:
You can use [Symfony HttpClient]([[= symfony_doc =]]/http_client.html) to test REST API.
Open a PHP shell in a terminal with php -a and copy-paste this code into it:
[[= include_file('code_samples/api/rest_api/load_content.php', 2, 9) =]]$resource URI should be edited to address the right domain.
On a freshly installed [[= product_name =]], 52 is the Content ID of the home page.
If necessary, substitute 52 with the content ID of an item from your database.
For a content creation example that uses PHP, see Creating content with binary attachments
The REST API can help you implement JavaScript / AJAX interaction.
The following example of an AJAX call retrieves ContentInfo (that is, metadata) for a content item.
To test it, copy-paste this code into your browser console alongside a page from your website (to share the domain):
=== "Fetch API"
```javascript
const resource = '/api/ibexa/v2/content/objects/52';
fetch(resource, {
headers: {'Accept': 'application/vnd.ibexa.api.ContentInfo+json'},
}).then((response) => {
console.log(...response.headers);
return response.json();
}).then((data) => {
console.log(data);
});
```
=== "XMLHttpRequest"
```javascript
const resource = '/api/ibexa/v2/content/objects/52';
const request = new XMLHttpRequest();
request.open('GET', resource, true);
request.setRequestHeader('Accept', 'application/vnd.ibexa.api.ContentInfo+json');
request.onload = function () {
console.log(request.getAllResponseHeaders(), JSON.parse(request.responseText));
};
request.send();
```
On a freshly installed [[= product_name =]], 52 is the Content ID of the home page.
If necessary, substitute 52 with the Content ID of an item from your database.
You can edit the resource URI to address another domain, but cross-origin requests must be allowed first.