Sugar Network/API: Difference between revisions
No edit summary |
|||
| Line 9: | Line 9: | ||
The API is [[Wikipedia:Restful|RESTful]] and being served via HTTP(S) using [[Wikipedia:Json|JSON]] notation. The common RESTful request url format is: | The API is [[Wikipedia:Restful|RESTful]] and being served via HTTP(S) using [[Wikipedia:Json|JSON]] notation. The common RESTful request url format is: | ||
http[s]://<SERVER>/<RESOURCE>[/<GUID | http[s]://<SERVER>[/<RESOURCE>[/<GUID>[/<PROPERTY>]]][?[cmd=<COMMAND>][&<ARGUMENT>=<VALUE>..]] | ||
When: | When: | ||
* | * {{Code|SERVER}}, particular Sugar Network API server, e.g., http://api-testing.network.sugarlabs.org; | ||
* | * {{Code|RESOURCE}}, name one of the [[#Resources|existing]] resources; | ||
* | * {{Code|GUID}}, the {{Code|RESOURCE}}'s particular object; | ||
* {{Code|PROPERTY}}, particular property of {{Code|GUID}} object; | |||
* {{Code|COMMAND}}, optional command name; combination of HTTP request method ({{Code|GET}}, {{Code|POST}}, {{Code|PUT}}, or, {{Code|DELETE}}) and [possibly empty] {{Code|COMMAND}} composes the requested [[#Actions|action]]; | |||
* {{Code|ARGUMENT}}s and {{Code|VALUE}}s depend on particular [[#Actions|action]]. | |||
If request needs to send data, it should send Python dictionary converted to [[Wikipedia:Json|JSON]] notation. | If request needs to send data, it should send Python dictionary converted to [[Wikipedia:Json|JSON]] notation. | ||
In most cases (see [[#Actions|actions]] for exceptions), server replies with dictionary in JSON notation. If request was failed, the replied dictionary will contain {{Code|request}}, with original request, and {{Code|error}}, with error message, keys. Otherwise, dictionary keys in response will be set accordingly to the particular request. | |||
== | == Resources == | ||
{{:Platform_Team/Sugar_Network/Objects_model}} | |||
Actions | == Actions == | ||
List of actions common of all resources. | |||
Dictionary | '''POST''' /<RESOURCE> | ||
: ''RESOURCE' | |||
Create new resource object. | |||
Dictionary to send: | |||
: {{Code|''RESOURCE}}'s properties. | |||
Dictionary keys to receive: | Dictionary keys to receive: | ||
:* {{Code|guid}}, with globally unique identifier that specifies created object. | :* {{Code|guid}}, with globally unique identifier that specifies created object. | ||
'''PUT''' /<RESOURCE>/<GUID> | |||
Modify resource object. By default, might be called only by {{Code|GUID}} creator. | |||
Dictionary to send: | |||
: {{Code|RESOURCE}}'s properties to modify. | |||
'''DELETE''' /<RESOURCE>/<GUID> | |||
Delete resource object. The real destroying won't happen, the object will be hidden. The garbage collection of hidden objects will be processed by Network administrators. By default, might be called only by {{Code|GUID}} creator. | |||
GET /<RESOURCE>?offset=<INTEGER>&limit=<INTEGER>[&query=<STRING>][&reply=<PROP>[,..]][&order_by=<nowiki>[+|-]</nowiki><PROP>][&<QUERY_PROP>=<VALUE>[&...]] | '''GET''' /<RESOURCE>?offset=<INTEGER>&limit=<INTEGER>[&query=<STRING>][&reply=<PROP>[,..]][&order_by=<nowiki>[+|-]</nowiki><PROP>][&group_by=<PROP>][&<QUERY_PROP>=<VALUE>[&...]] | ||
Find | Find resource objects. | ||
Where: | Where: | ||
| Line 60: | Line 69: | ||
:* {{Code|QUERY_PROP}}, ''str''<br>supplement {{Code|query}} with filtering by property value, the resulting query string will be {{Code|<nowiki>QUERY_PROP=VALUE AND (query)</nowiki>}}; | :* {{Code|QUERY_PROP}}, ''str''<br>supplement {{Code|query}} with filtering by property value, the resulting query string will be {{Code|<nowiki>QUERY_PROP=VALUE AND (query)</nowiki>}}; | ||
:* {{Code|reply}}, ''str''<br>coma separated list of ''RESOURCE'' properties to return; by default, return only {{Code|guid}} property; | :* {{Code|reply}}, ''str''<br>coma separated list of ''RESOURCE'' properties to return; by default, return only {{Code|guid}} property; | ||
:* {{Code|order_by}}, ''str''<br>property to sort the resulting list by; if starts with the {{Code|-}}, the order is descending, otherwise it is ascending. | :* {{Code|order_by}}, ''str''<br>property to sort the resulting list by; if starts with the {{Code|-}}, the order is descending, otherwise it is ascending; | ||
:* {{Code|group_by}}, ''str''<br>property name to group resulting list by. | |||
Dictionary keys to receive: | Dictionary keys to receive: | ||
:* {{Code|total}}, total number in requested query (the reply might contain only portion restricted by {{Code|limit}} request argument); | :* {{Code|total}}, total number in requested query (the reply might contain only portion restricted by {{Code|limit}} request argument); | ||
:* {{Code|result}}, an array of dictionaries with | :* {{Code|result}}, an array of dictionaries with resource object properties, dictionaries contain at least {{Code|guid}} property. | ||
'''GET''' /<RESOURCE>/<GUID>[?reply=<PROP>[,..]] | |||
Return properties for particular resource object. | |||
Dictionary keys to receive: | Dictionary keys to receive: | ||
:* | :* properties that were specified in {{Code|reply}} argument(s), at least {{Code|guid}}. | ||
'''GET''' /<RESOURCE>/<GUID>/<PROPERTY>[?reply=<PROP>[,..]] | |||
Return property value for particular resource object. | |||
Data to receive: | |||
:* property value in JSON notation. | |||
* | |||
== Getting involved == | == Getting involved == | ||
{{:Sugar_Network/Feedback}} | {{:Sugar_Network/Feedback}} | ||