Jump to: navigation, search

Difference between revisions of "Horizon/RESTAPI"

(POST requests)
(POST requests)
Line 38: Line 38:
 
| Content-Type || application/json
 
| Content-Type || application/json
 
|-
 
|-
| X-CSRFToken || the value of the csrftoken cookie you've seen in any GET request to the same address. I obtained the token by opening another tab, doing a create or delete action while using the developer tools to sniff the POST network requests. Maybe there's a better way?
+
| X-CSRFToken || the value of the csrftoken cookie you've seen in any GET request to the same address. You can obtain the token from the cookie sent via your REQUEST headers of the above GET call.
 
|}
 
|}
  

Revision as of 21:28, 19 February 2015

Horizon REST API

Horizon has a REST API that allows client side code to make API through the Horizon server without DJANGO server side rendering. This is to support the angular work being done in Horizon. It takes care of issues like cross origin resource scripting as well as leveraging authentication and authorization libraries already in existence.

THE API ARE FOR THE EXCLUSIVE USE OF HORIZON DEVELOPMENT AND ARE NOT SUPPORTED FOR EXTERNAL USE AT THIS TIME

Testing

To Test the Horizon REST APIs using POSTMAN (Chrome Plugin), login normally going to the exact API address (or localhost) that you'll use from POSTMAN. Once you've logged in your browser will have an access cookie that it'll pass on with all its requests.

GET requests

Input the URL.

For exampleː http://127.0.0.1:8005/api/glance/images

Set the following header:

Header Value
X-Requested-With XMLHttpRequest

The GET requests should include a csrftoken cookie (eg. csrftoken=onXnBfMqIxuFGr437P91Uuxdl09t2ykQ). You should copy this off if you need to perform any POST requests.

POST requests

Input the URL.

For exampleː http://127.0.0.1:8005/api/nova/keypairs/

Set the following headers

Header Value
X-Requested-With XMLHttpRequest
Content-Type application/json
X-CSRFToken the value of the csrftoken cookie you've seen in any GET request to the same address. You can obtain the token from the cookie sent via your REQUEST headers of the above GET call.

Set the raw content as JSON formatted.

Exampleː

{
 "name":"foo" 
}