Difference between revisions of "Sugar Network/API"

From Sugar Labs
Jump to navigation Jump to search
 
(156 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This page describes the APi that Sugar Network clients use to interact with Sugar Network server. See also [[Sugar_Network|technical introduction]] page.
+
This page describes the API that Sugar Network clients use to interact with a Sugar Network server. See also a guide to basic Sugar Network [[Sugar_Network/Concept|concepts]] and [[Platform_Team/Sugar_Network/Architecture|its twin page]] for a technical point of view. In addition, visit the [[Sugar_Network|introduction page]].
 +
 
 +
{{Note/warning|Note|Until announcing API freeze, this document describes the most recent development version of the API.<br>You can find its implementation on the [[#API servers|node-devel.sugarlabs.org]] server.}}
  
 
== Overview ==
 
== Overview ==
  
The API operates with [[#Resources|resources]] that are collections of objects. All objects are identified by global unique identifiers, GUIDs. Resources might support [[#Aactions|common actions]]. While processing requests, server might generate [[#events|events]]. There are [[#Events|common events]] that all resources might generate.
+
To better understand this API, see a technical explanation of its [[Platform_Team/Sugar_Network/Architecture#Conceptual_level|conceptual level]] and [[#Sugar_Network_resources|objects model]] in particular.
 +
 
 +
The API operates with [[Sugar Network]] [[#Sugar_Network_resources|resources]], which are collections of objects. All objects are identified by globally unique identifiers, GUIDs, and available for operation via [[#Base_API|basic actions]]. The API is being provided from a [[#API_servers|node server]] or a [[#Client_API|client]]. While processing requests, API providers generate [[#Notifications|events]].
  
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 is served via HTTP(S) using [[Wikipedia:Json|JSON]] notation. The common request url format is:
  
  http[s]://<SERVER>/<RESOURCE>[/<GUID|ACTION>[/<ACTION>]]?<AUTH-TOKEN>=<>[&<ARG>=<>]..]
+
  http[s]://''SERVER''[/''RESOURCE''[/''GUID''[/''PROPERTY'']]][?[cmd=''COMMAND''][&''ARGUMENT''=''VALUE''..]]
  
 
When:
 
When:
  
* ''RESOURCE'' value is one of [[#Resources|existing]] resources;
+
* {{Code|SERVER}}, [[#API_servers|particular]] Sugar Network API server;
* ''GUID'', the ''RESOURCE'''s particular object;
+
* {{Code|RESOURCE}}, name one of the [[#Sugar_Network_resources|existing]] resources;
* ''ACTION'' and a set of ''ARG''s depend on particular ''RESOURCE''.
+
* {{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 the particular [[#Actions|action]].
 +
 
 +
In most cases, the server replies in JSON notation. If a request fails, the replied JSON object will contain a {{Code|request}} key, with the original request, and {{Code|error}} key, with an error message.
 +
 
 +
== API version ==
 +
 
 +
Sugar Network nodes might support multiple API versions at once but only one of them is default, i.e., the one which is in use if clients do not specify particular API version. To specify API versions in client request, setup the {{Code|X-API}} HTTP header with chosen version. If such header is omitted, default version will be used by the node;
 +
 
 +
Currently available API versions:
 +
 
 +
* ''0.1'' initial API implementation, should not be used;
 +
* ''0.2'' the most recent version, the rest of the document describes exactly this version.
  
Besides, particular request can send and receive data in [[Wikipedia:Json|JSON]] notation. If request processing was failed, the reply is a JSON directory that contains {{Code|error}} key with error message.
+
== Nodes ==
  
For the beginning, API is not secure for reasons:
+
These are standard Sugar Network API servers publicly available.
  
* Implement initial version in short period of time;
+
* [http://node-devel.sugarlabs.org/ node-devel.sugarlabs.org]<br>Development server which does not contain important data and is free for any experiments (administrative privileges for anonymous users); default API version is ''0.2'';
* The only users, for the beginning, are teachers and students from one-teacher off-line schools.
 
  
In particular:
+
* [http://node-testing.sugarlabs.org/ node-testing.sugarlabs.org]<br>Recent stable release with regular data import from the production server; is still free for any experiments; default API version is ''0.1'';
  
* API is being provided only via HTTP;
+
* [http://node.sugarlabs.org/ node.sugarlabs.org]<br>Production server;
* The ''AUTH-TOKEN'' is the {{Code|uid}} which is a hashed value from Sugar profile public SSH key (the same as JID value in Sugar Shell but without the domain part) that does not require any handshake procedures.
 
  
== Commons ==
+
* [http://localhost:5001/ localhost:5001]<br>default url to get access to [[#Client_API|local proxy]] provided from user side application; ; default API version is ''0.1''.
  
=== Properties ===
+
== Resources ==
  
All resources have the following properties:
+
{{:Sugar_Network/Resources}}
  
* {{Code|guid}}, ''guid''<br>the global unique identifier of the object;
+
== Base API ==
* {{Code|ctime}}, ''int''<br>the UNIX seconds in UTC timezone of the time when object was created; optional, will be set on a server side otherwise;
 
* {{Code|mtime}}, ''int''<br>the UNIX seconds in UTC timezone of the time when object was modified; optional, will be set on a server side otherwise;
 
* {{Code|creator}}, ''guid'', ''read''<br>the ''player'' who created the object.
 
  
Resources that can be voted (everything except ''player'', ''report'', ''comment'' and ''event''), have these additional properties:
+
List of actions common of all API providers.
  
* {{Code|respect}}, ''guid'', ''read'', ''create''<br>what ''player'' needs to be respected on getting vote to this object, if empty, the associated ''project'' itself will be voted.
+
<div id="POST"></div>
  
And calculated ones:
+
'''POST''' /''RESOURCE''
* {{Code|reputation}}, ''int'', ''read''<br>current object's reputation;
 
* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not.
 
  
=== Actions ===
+
Create new resource object.
  
Actions might be restricted for particular resource, see the corresponding section for detailed information.
+
JSON object keys to send:
 +
* {{Code|''RESOURCE}}'s properties.
  
POST /<RESOURCE>
+
JSON object keys to receive:
 +
* {{Code|guid}}, with globally unique identifier that specifies the created object.
  
Create new ''RESOURCE'' object.
+
<div id="PUT"></div>
  
Sends:
+
'''PUT''' /''RESOURCE''/''GUID''
: Resource properties.
 
  
Receives:
+
Modify resource object. By default, might be called only by {{Code|GUID}} creator.
:* {{Code|guid}}, ''str''<br>globally unique identifier that specifies created object;
 
  
PUT /<RESOURCE>/<GUID>
+
JSON object keys to send:
 +
* {{Code|RESOURCE}}'s properties to modify.
  
Modify the specified ''RESOURCE'' object. By default, might be called only by ''RESOURCE'' creator.
+
<div id="DELETE"></div>
  
Sends:
+
'''DELETE''' /''RESOURCE''/''GUID''
: Keys that need to be modified.
 
  
DELETE /<RESOURCE>/<GUID>
+
Delete resource object. Actual object destruction won't happen, the object will be hidden. Garbage collection of hidden objects will be processed by Network administrators. By default, this action may be called only by the {{Code|GUID}} creator.
  
Delete the specified ''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 ''RESOURCE'' creator.
+
<div id="GET"></div>
  
  GET /<RESOURCE>?[query=<>][&offset=<>][&limit=<>][&properties=<PROP>[,..]][&order_by=<nowiki>[+|-]</nowiki><PROP>[,..]]
+
  '''GET''' /''RESOURCE''[?offset=''INTEGER''][&limit=''INTEGER''][&query=''STRING''][&reply=''PROP''][&order_by=<nowiki>[+|-]</nowiki>''PROP''][&group_by=''PROP''][&''PROP''=''VALUE''][&''!PROP''=''VALUE'']
  
Find ''RESOURCE'' objects.
+
Find resource objects.
  
 
Where:
 
Where:
:* {{Code|query}}, ''str''<br>search request in [http://xapian.org/docs/queryparser.html Xapian] notation;
+
* {{Code|offset}}, ''int''<br>start index to return entries from, the default value is {{Code|0}};
:* {{Code|offset}}, ''int''<br>start index to return entries from;
+
* {{Code|limit}}, ''int''<br>do not return more then specified value, maximal and default values are being setup on server side;
:* {{Code|limit}}, ''int''<br>do not return more then specified value;
+
* {{Code|query}}, ''str''<br>search request in [http://xapian.org/docs/queryparser.html Xapian] notation; if property is boolean, integer or datetime, it supports searching by ranges, i.e., {{Code|''PROP'':[''START'']..[''END'']}};
:* {{Code|properties}}, ''str''<br>coma separated list of ''RESOURCE'' properties to return; by default, return all properties;
+
* {{Code|PROP}}, ''str''<br>supplements {{Code|query}} with filtering by exact value of the {{Code|PROP}} property; the resulting query string will be {{Code|''PROP''<nowiki>=</nowiki>''VALUE'' AND (''QUERY'')}}; argument is multiple;
:* {{Code|order_by}}, ''str''<br>coma separated list of ''RESOURCE'' properties to sort the resulting list; if an property starts with the {{Code|-}}, the order is descending, otherwise it is ascending;
+
* {{Code|!PROP}}, ''str''<br>supplements {{Code|query}} by excluding exact value of the {{Code|PROP}} property; the resulting query string will be {{Code|NOT ''PROP''<nowiki>=</nowiki>''VALUE'' AND (''QUERY'')}}; argument is multiple;
 +
* {{Code|reply}}, ''str''<br>''RESOURCE'' properties to return; by default, return only {{Code|guid}} property; argument is multiple;
 +
* {{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.
 +
 
 +
JSON object keys to receive:
 +
* {{Code|total}}, total number in requested query (the reply might contain only the portion restricted by {{Code|limit}} request argument);
 +
* {{Code|result}}, an array of dictionaries with resource object properties, dictionaries contain at least {{Code|guid}} property.
 +
 
 +
<div id="GET-resource"></div>
 +
 
 +
'''GET''' /''RESOURCE''/''GUID''[?reply=''PROP'']
 +
 
 +
Where:
 +
* {{Code|reply}}, ''str''<br>''RESOURCE'' properties to return; by default, return only {{Code|guid}} property; argument is multiple;
 +
 
 +
Return properties for a particular resource object.
 +
 
 +
JSON object keys to receive:
 +
* properties that were specified in {{Code|reply}} argument(s), at least {{Code|guid}}.
 +
 
 +
<div id="PUT-property"></div>
 +
 
 +
'''PUT''' /''RESOURCE''/''GUID''/''PROP''
 +
 
 +
Modify particular resource property. By default, might be called only by {{Code|GUID}} creator.
 +
 
 +
<div id="GET-property"></div>
 +
 
 +
'''GET''' /''RESOURCE''/''GUID''/''PROP''
 +
 
 +
Return property value for particular resource object.
 +
 
 +
Data to receive:
 +
* property value in JSON notation for regular properties;
 +
* raw data or redirection for BLOB properties.
  
Sends:
+
=== Aggregated properties ===
:* A dictionary with ''RESOURCE'''s properties to restrict the resulting list.
 
  
Receives:
+
[[#resource-types|Aggregated]] properties have special API to treat their content.
:* An array of dictionaries with ''RESOURCE'' properties, dictionaries contain at least {{Code|guid}} property.
 
  
GET /<RESOURCE>/<GUID>[?properties=<PROP>[,..]]
+
<div id="POST-aggproperty"></div>
  
Return ''RESOURCE'' properties the of particular object.
+
'''POST''' /''RESOURCE''/''GUID''/''PROP''
  
Where:
+
Submit new item. The command returns an id for newly created aggregated item. Depending on particular property, new items might be created not only by object's authors.
:* {{Code|properties}}, ''str''<br>coma separated list of ''RESOURCE'' properties to return; by default, return all properties.
+
 
 +
<div id="PUT-aggproperty"></div>
  
Receives:
+
'''PUT''' /''RESOURCE''/''GUID''/''PROP''/''ID''
:* A dictionary with ''RESOURCE'' properties that contains at least {{Code|guid}} property.
 
  
=== Wiki actions ===
+
Update existing aggregated item. Depending on particular property, the command is allowed either to object's authors or to aggregated item submitter.
  
Some of resources have Wiki pages associated. The following actions can be used to manage these Wiki pages.
+
<div id="DELETE-aggproperty"></div>
  
  GET /<RESOURCE>/<GUID>/'''wikitext'''
+
  '''DELETE''' /''RESOURCE''/''GUID''/''PROP''/''ID''
  
Get the Wiki sources.
+
Delete existing aggregated item. Depending on particular property, the command is allowed either to object's authors or to aggregated item submitter.
  
Receives:
+
=== Notifications ===
: Wiki sources with text/plain MIME type.
 
  
GET /<RESOURCE>/<GUID>/'''rendered_wikitext'''
+
It is possible to subscribe to server events. Notification will happen using HTML5 [[wikipedia:Server-sent_events|Server-sent events]] (SSE).
  
Get the Wiki rendered to HTML.
+
To start subscription, send the following request:
  
Receives:
+
'''GET''' /?cmd='''subscribe'''
: Rendered Wiki with text/html MIME type.
 
  
PUT /<RESOURCE>/<GUID>/'''wikitext'''
+
Response will be served with ''text/event-stream'' MIME type for default SSE message type. SSE message will be a JSONified object with the following, at least, attributes:
  
Put new content for Wiki page. Only object creator can use it.
+
* {{Code|event}}<br>event type.
  
Sends:
+
== Node API ==
: Wiki sources with text/plain MIME type.
 
  
Events:
+
This is an API provided by Sugar Network nodes on top of [[#Base_API|base one]].
: {{Code|type: update}}
 
  
=== Events ===
+
=== Authentication ===
  
All events have the following common properties:
+
Right now, the only way to be authenticated on a Sugar Network server is by running a [[Platform_Team/Sugar_Network/Implementation#sugar-network-client|local application]] on the client side and using the API it [[#Client_API|provides]].
  
* {{Code|type}}, ''str''<br>the type of event;
+
''TODO''
* {{Code|timestamp}}, ''int''<br>the UNIX seconds in UTC timezone of the time when event was created;
 
* {{Code|resource}}, ''str''<br>the name of affected resource;
 
* {{Code|object}}, ''guid''<br>the GUID of affected resource object;
 
* {{Code|creator}}<br>the GUID of a ''player'' the event was created on behalf of.
 
  
Different types of events might add new options.
+
=== Authorization ===
  
There are the following common event types:
+
Read-only access is available for anonymous requests, except special content like machine serial numbers. But to process any changes, clients need to be authenticated.
  
: The particular resource was created:
+
Right after creating any Sugar Network object, its author becomes the only user who can process any object modifications afterwards. Authority information will be kept in the [[#Sugar_Network_resources|author]] property and can be modified using the following commands.
:* {{Code|type: create}}
 
  
: The particular resource properties were modified:
+
'''PUT''' /''RESOURCE''/''GUID''?cmd='''useradd'''&user=''USER''&role=''ROLE''
:* {{Code|type: update}}
 
  
: The particular resource was deleted (hidden):
+
Add another user who can modify the corresponding object. ''USER'' argument should be either ''User'' guid (for authors registered in the Sugar Network), or, full author name.
:* {{Code|type: delete}}
 
  
== Resources ==
+
'''PUT''' /''RESOURCE''/''GUID''?cmd='''userdel'''&user=''USER''
  
=== player ===
+
Remove user from the authority list. It is not possible to remove yourself. ''USER'' argument should be either ''User'' guid (for authors registered in the Sugar Network), or, full author name.
  
Properties:
+
''TODO''
:* {{Code|nickname}}, ''str'', ''read''<br>set by Sugar Shell;
 
:* {{Code|color}}, ''str'', ''read''<br>colors pair in format {{Code|#RRGGBB,#RRGGBB}}, set by Sugar Shell.
 
  
Calculated properties:
+
=== Retrieving releases ===
:* {{Code|reputation}}, ''int'', ''read''<br>current ''player'''s reputation based on:
 
:** direct votes from other players,
 
:** votes given to objects where the ''player'' is a creator;
 
:* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not;
 
  
Actions:
+
To easy download Context [[#context-releases|releases]] and avoid reading raw ''Context.releases'' property, there are special high-level API commands.
  
* ''player'' cannot be created or destroyed;
+
<div id="GET-solve"></div>
* ''player'' can be updated only by a user who is associated with it.
 
  
  POST /player/<GUID>/'''message'''
+
  '''GET''' /context/''GUID''?cmd='''solve'''[&lsb_id=''LSB_ID''][&lsb_release=''LSB_RELEASE''][&assume=''DEPENDENCY''-''VERSION'']
  
Send private message to the ''player''.
+
The command returns information about what particular releases should be downloaded depending on provided requirements. This command might return not only one release, e.g., activities might have dependencies either system packages or another Sugar Network Contexts.
  
Sends:
+
Solving requirements might be:
: A dictionary with [[#event|event]] properties.
 
  
Events:
+
* {{Code|LSB_ID}}, if Context releases depend on system packages, specify the [[Wikipedia:Linux_Standard_Base|LSB]] distributor id to consider while choosing particular packages;
: Direct event to the ''player'':
+
* {{Code|LSB_RELEASE}}, if Context releases depend on system packages, specify the [[Wikipedia:Linux_Standard_Base|LSB]] release number of the distribution to consider while choosing particular packages;
:* {{Code|type: message}}.
+
* {{Code|DEPENDENCY-VERSION}}, the {{Code|assume}} argument instructs server to assume that specified [[Sugar_Network/Recipe_Specification#Dependencies|dependency]] is already available on client side and should be taken into account while solving; this is especially important for package dependencies when server considers packages available only from official repositories but users might have more recent package versions installed in local system; e.g., the above example request will fail without {{Code|sugar-0.94}} because neither {{Code|lsb_id}} nor {{Code|lsb_release}} were specified (even if LSB information is passed, server might not have information about what package versions come from official repositories).
  
=== project ===
+
The resulting info is a JSON object with keys equal to Context guids and value objects for chosen release with the following keys:
  
Properties:
+
* {{Code|blob}}, bundle [[#resource-types|digest]] to download;
:* {{Code|title}}, ''str'', ''read'', ''write'' only for the team members<br>one line title;
+
* {{Code|version}}, chosen version number;
description;
+
* {{Code|title}}, the ''Context.title'' value;
:* {{Code|type}}, ''str'', ''read'', ''write'' only for the team members<br>the project type:
+
* {{Code|command}}, a command to launch the bundle, only for Sugar activities.
:** {{Code|general}},
 
:** {{Code|activity}},
 
:** {{Code|wiki}},
 
:** {{Code|gallery}};
 
:* {{Code|zoom}}, ''str'', ''read'', ''write'' only for the team members<br>Network Zoom level that project belongs:
 
:** {{Code|worldwide}},
 
:** {{Code|neighbourhood}},
 
:** {{Code|private}}.
 
  
Calculated properties:
+
For example, the {{Code|'''GET''' <nowiki>/context/org.laptop.TurtleArtActivity?cmd=solve&assume=sugar-0.94</nowiki>}} request returns:
:* {{Code|reputation}}, ''int'', ''read''<br>current ''project'''s reputation based on:
 
:** direct votes from other players,
 
:** votes given to related objects if theirs ''respect'' property is empty;
 
:* {{Code|vote}}, ''bool'', ''read'', ''write''<br>did url requester voted for the current object or not.
 
  
Actions:
+
{
 +
  "org.laptop.TurtleArtActivity": {
 +
    "title": "Turtle Blocks",
 +
    "version": "202",
 +
    "blob": "http://download.sugarlabs.org/activities/4027/turtleblocks-202.xo",
 +
    "content-type": "application/vnd.olpc-sugar",
 +
    "size": 4715955,
 +
    "unpack_size": 12873871,
 +
    "command": "sugar-activity TurtleArtActivity.TurtleArtActivity",
 +
  },
 +
  "sugar": {
 +
    "version": "0.94",
 +
  },
 +
}
  
* right after creation, the creator will be the only ''team'' member;
+
<div id="GET-clone"></div>
* update and delete actions are allowed only for ''team'' members;
 
* [[#Wiki_actions|Wiki related actions]] to manage object description.
 
  
POST /project/<GUID/'''add_member'''?member=<PLAYER>
+
Like the [[#GET-solve|solve]] command, ''clone'' makes a solution but returns bundle itself, so, there is no way to get information about possible dependencies.
  
Make a ''PLAYER'' the ''team'' member. Only ''team'' members can call this action.
+
'''GET''' /context/''GUID''?cmd='''clone'''[&lsb_id=''LSB_ID''][&lsb_release=''LSB_RELEASE''][&assume=''DEPENDENCY''-''VERSION'']
  
Events:
+
=== Upload releases ===
:* {{Code|type: add_member}};
 
:* {{Code|memeber: GUID}}.
 
  
POST /project/GUID/'''remove_member'''?member=<PLAYER>
+
To easy upload Context [[#context-releases|releases]] and avoid writing to raw ''Context.releases'' property, there is a special high-level API command.
  
Remove ''PLAYER'' from the to the ''team''. Only ''team'' member can call this action if he is not the ''PLAYER'' and ''PLAYER'' is not the same as ''creator''.
+
'''POST''' /context?cmd='''submit'''[&''PROP''=''VALUE''][&initial]
  
Events:
+
Where the {{Code|PROP}} arguments are optional release properties. The {{Code|initial}} argument asks the system to create new Context resource new release will belong to.
:* {{Code|type: remove_member}};
 
:* {{Code|memeber: GUID}}.
 
  
=== question ===
+
The posting data might be two types,
  
Properties:
+
* Sugar activities in .xo bundles,<br>there is no need in {{Code|PROP}} arguments, all properties will be populated basing on metadata from a .xo bundle; including release notes from the {{Code|CHANGELOG}} file in [[Wikipedia:Markdown|Markdown]] notation; besides, only in this case {{Code|initial}} makes sense because it is the only way to get Context properties;
:* {{Code|project}}, ''guid'', ''read''<br>the ''project'' this object belongs to;
 
:* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title;
 
:* {{Code|solution}}, ''guid'', ''read'', ''write'' only by creator<br>the ''solution'' which solves the object.
 
  
Calculated properties:
+
* Arbitrary data,<br>all required release properties should be specified in {{Code|PROP}} arguments, at least ''context'' and ''version''; ''license'' should be specified only if there are no existing releases to pickup license from.
:* {{Code|implementation_status}}, ''str'', ''read''<br>if ''question'' has an associated ''objective'', this ''objective'''s status is a status of the ''question'', otherwise the property is empty.
 
  
Actions:
+
=== Node statistics ===
* [[#Wiki_actions|Wiki related actions]] to manage object description.
 
  
=== idea ===
+
The node statistics are about the entire server and depersonalized. Statistics are being collected by analyzing regular requests to an API server and stored for each Sugar Network node. To read such info, call the command:
  
Properties:
+
'''GET''' /?cmd='''stats'''[&start=''SECONDS''][&end=''SECONDS''][&event=''EVENT''][&limit=''NUMBER'']
:* {{Code|project}}, ''guid'', ''read''<br>the ''project'' this object belongs to;
 
:* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title.
 
  
Calculated properties:
+
Where:
:* {{Code|implementation_status}}, ''str'', ''read''<br>if ''idea'' has an associated ''objective'', this ''objective'''s status is a status of the ''idea'', otherwise the property is empty.
 
  
Actions:
+
* {{Code|start}} and {{Code|end}} is a time interval to get statistics for; if omitted, the beginning and the end of entire life cycle will be used;
* [[#Wiki_actions|Wiki related actions]] to manage object description.
+
* {{Code|event}}, multiple argument to specify what stats should be returned; if omitted, return all sources;
 +
* {{Code|limit}}, number of stat records to return for the {{Code|start}}-{{Code|end}} interval; note that this amount is not precise, the final resultset might be smaller or bigger depending on chosen resolution; stats resolution depends on node configuration, default values are 1 day, 10 days, 30 days, 365 days; if omitted, return {{Code|end}} record only.
  
=== problem ===
+
Possible events are:
  
Properties:
+
* {{Code|users}}, total number of existing ''User'' objects;
:* {{Code|project}}, ''guid'', ''read''<br>the ''project'' this object belongs to;
+
* {{Code|contexts}}, total number of existing ''Context'' objects;
:* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title;
+
* {{Code|released}}, average number of newly uploaded ''Context.releases'' for specified time frame;
:* {{Code|solution}}, ''guid'', ''read'', ''write'' only by creator<br>the ''solution'' which solves the object.
+
* {{Code|solved}}, average number of requested ''Context'' [[#GET-solve|solutions]] for specified time frame; note that this value does not equal to the number of solution usages on client side since solutions might be cached;
 +
* {{Code|reported}}, average number of newly uploaded failure ''Report'' objects for specified time frame;
 +
* {{Code|topics}}, total number of top-level ''Post'' objects;
 +
* {{Code|posts}}, total number of dependent ''Post'' objects.
  
Calculated properties:
+
== Client API ==
:* {{Code|implementation_status}}, ''str'', ''read''<br>if ''problem'' has an associated ''objective'', this ''objective'''s status is a status of the ''problem'', otherwise the property is empty.
 
  
Actions:
+
The reasons to proxy Sugar Network data on users side:
* [[#Wiki_actions|Wiki related actions]] to manage object description.
 
  
=== wiki ===
+
* Seamless support [[#Offline mode|offline workflow]];
 +
* [[#Launching|One-click launch]] Sugar activities hosted on Sugar Network.
  
Properties:
+
Proxying happens by providing the same Sugar Network API (with some extra functionality, see below) from
:* {{Code|project}}, ''guid'', ''read''<br>the ''project'' this object belongs to;
+
[[Platform_Team/Sugar_Network/Implementation#sugar-network-client|local process]] launched beforehand.
:* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title.
 
  
Actions:
+
=== Offline mode ===
* [[#Wiki_actions|Wiki related actions]] to manage Wiki page.
 
  
=== gallery ===
+
Being connected to a Sugar Network node, local proxy provides [[#Node_API|original API]] from the node. If the connection is lost, the proxy will switch to local Sugar Network storage and continue working providing only [[#Base_API|base API]]. Any content created in offline mode will be uploaded to the node after getting a connection back.
  
Properties:
+
Besides, local Sugar Network storage will be reused to keep users preferences, such as:
:* {{Code|project}}, ''guid'', ''read''<br>the ''project'' this object belongs to;
 
:* {{Code|title}}, ''str'', ''read'', ''write'' only for creator<br>one line title.
 
  
Actions:
+
* Favorited Contexts<br>to select preferred ''Context'' resources; these Contexts will be marked by {{Code|favorite}} value in the ''Context.layer'' property;
* [[#Wiki_actions|Wiki related actions]] to manage object description.
 
  
GET /gallery/<GUID>/'''exhibit'''
+
* Checked-in Contexts<br>to keep most recent Context (for ''activity'' and ''book'' types) version in local storage to make it available in offline; note that there is no need in checking-in to speedup online lunch, versions are being [[#Launching|cached]] anyway; these Contexts will be marked by {{Code|checkin}} value in the ''Context.layer'' property.
  
Get the attached object.
+
To control users preferences there are special API commands:
  
Receives:
+
<div id="PUT_favorite"></div>
: Attached object content with application/octet-stream MIME type.
 
  
  PUT /gallery/<GUID>/'''exhibit'''
+
  '''PUT''' /context/''GUID''?cmd='''favorite'''
  
Put new attached object. Only object creator can use it.
+
Set favorite status.
  
Sends:
+
<div id="DELETE_favorite"></div>
: Attached object content with application/octet-stream MIME type.
 
  
Events:
+
'''DELETE''' /context/''GUID''?cmd='''favorite'''
: {{Code|type: update}}
 
  
=== objective ===
+
Unset favorite status.
  
Properties:
+
<div id="PUT_checkin"></div>
:* {{Code|project}}, ''guid'', ''read''<br>the ''project'' this object belongs to;
 
:* {{Code|title}}, ''str'', ''read'', ''write'' only for the team members<br>one line title.
 
  
Actions:
+
'''PUT''' /context/''GUID''?cmd='''checkin'''[&spawn]
* [[#Wiki_actions|Wiki related actions]] to manage object description.
 
  
=== release ===
+
Check-in the specified Context. By default, the command will return streamed ''text/event-stream'' MIME type data to monitor the progress. If the {{Code|spawn}} argument is specified, the command will exit immediately with [[#Notifications|asynchronous sending]] progress events.
  
Properties:
+
<div id="DELETE_checkin"></div>
:* {{Code|project}}, ''guid'', ''read''<br>the ''project'' this object belongs to;
 
:* {{Code|version}}, ''str'', ''read''<br>release version;
 
:* {{Code|stability}}, ''str'', ''read''<br>release stability level, the same as for Zero Install/Sweets.
 
  
Actions:
+
'''DELETE''' /context/''GUID''?cmd='''checkin'''
* [[#Wiki_actions|Wiki related actions]] to manage release notes.
 
  
=== report ===
+
Checkout the Context.
  
Properties:
+
=== Launching ===
:* {{Code|release}}, ''guid'', ''read''<br>the ''release'' this object belongs to.
 
  
Actions:
+
Sugar Network Contexts (for ''activity'' and ''book'' types) can be launched as-is. The launching process is implicit and includes selecting the most recent (and appropriate for software contexts) version, downloading bundles from the Sugar Network, installing missed [[Sugar_Network/Recipe_Specification#Dependencies|software dependencies]], execution itself. All downloaded bundles will be cached [with further garbage collecting] to speedup further launching.
  
: Only read-only [[#Actions|common]] actions.
+
Sugar activities will be directly executed. Book Contexts will be opened in the proper application according to its MIME type.
  
  PUT /report/<GUID>/'''logs'''
+
  '''GET''' /context/''GUID''?cmd='''launch'''[&args=''ARG''][&activity_id=''ACTIVITY_ID''][&object_id=''OBJECT_ID''][&uri=''URI''][&app=''APP''][&spawn]
  
Attach logs to the ''report''.
+
Arguments that make sense only for Sugar activities:
  
Sends:
+
* {{Code|ARG}}, command line argument to pass to launched activities, repeat {{Code|ARG}} for each argument;
: Attached logs with application/octet-stream MIME type.
+
* {{Code|ACTIVITY_ID}}, internal activity id which will be auto set if omitted;
 +
* {{Code|OBJECT_ID}}, Journal object id to resume;
 +
* {{Code|URI}}, URL to resume if activity supports this functionality.
  
Events:
+
Arguments that make sense only for books:
: {{Code|type: update}}
 
  
GET /report/<GUID>/'''logs'''
+
* {{Code|APP}}, specify application Context to open the book by; if omitted, the system will try to find most appropriate option, among all existing software Contexts.
  
Get ''report'' attached logs.
+
Common arguments:
  
Receives:
+
* {{Code|spawn}}, by default, the command will return streamed ''text/event-stream'' MIME type data to monitor the whole launching process until exiting the application; if the {{Code|spawn}} argument is specified, the command will exit immediately with [[#Notifications|asynchronous sending]] launching events.
: Attached logs with application/octet-stream MIME type.
 
  
=== solution ===
+
== Experimental API ==
  
The solution for ''question''/''idea''/''problem'' objects.
+
There is no guaranty that the following API will be stated as stable or frozen sometime.
  
Properties:
+
=== Access to Sugar Journal ===
:* {{Code|resource}}, ''str'', ''read''<br>the type of resource this solution is for;
 
:* {{Code|object}}, ''guid'', ''read''<br>the resource object this solution is for.
 
  
Actions:
+
It is possible to get access to local Sugar Journal using special, ''journal'', resource provided from [[#Client_API|client API]]. This kind of access might be useful when local applications cannot use DBus sugar-datastore API, e.g., [[wikipedia:Javascript|Javascript]] applications. API to Journal is restricted only to read-only access:
* [[#Wiki_actions|Wiki related actions]] to manage object description.
 
  
=== comment ===
+
'''GET''' /journal?offset=''INTEGER''&limit=''INTEGER''[&query=''STRING''][&order_by=<nowiki>[+|-]</nowiki>''PROP''][&''QUERY_PROP''=''VALUE''[&...]]
 +
'''GET''' /journal/''JOURNAL_ID''[?reply=''PROP''[,..]]
 +
'''GET''' /journal/''JOURNAL_ID''/''PROPERTY''
  
Properties:
+
== Usage ==
:* {{Code|resource}}, ''str'', ''read''<br>the type of resource this comment is about;
 
:* {{Code|object}}, ''guid'', ''read''<br>the resource object this comment is about;
 
:* {{Code|text}}, ''str'', ''read'', ''write'' only for creator<br>comment text.
 
  
=== event ===
+
Being HTTP based, Sugar Network API can be used in any manner regular HTTP requests can be handled. But for command-line access, there is a handy tool, {{Code|sugar-network}}, which takes care about Sugar Network specific like launching local API (if it is not already available) to get access to [[#Client_API|local proxy]].
  
Properties:
+
The sugar-network command-line format is below. Call {{Code|sugar-network --help}} for more detailed info.
: No specific properties except the [[#Events|common]] ones.
 
  
Actions:
+
sugar-network GET|POST|PUT|DELETE ''PATH'' ''ARG=VALUE'' [..]
: Only read-only [[#Actions|common]] actions.
 
  
== Getting involved ==
+
* {{Code|PATH}}, is an url path;
 +
* {{Code|ARG<nowiki>=</nowiki>VALUE}}, request arguments as they being passed to in url.
  
{{:Sugar_Network/Feedback}}
+
{{Code|POST}} and {{Code|PUT}} commands require data to pass, use the following command-line arguments:
  
== Changelog ==
+
* {{Code|-f FILE}} to specify the file to pass;
 +
* {{Code|-d DATA}} to specify string to pass;
 +
* {{Code|-j}} posted data should be encoded into JSON before posting.
  
This section shows how API is evolving. The API state is being described by a version. The major number is being changed only if backwards compatibility was broken.
+
== Getting involved ==
  
'''1.0'''
+
{{:Sugar_Network/Feedback}}
: Not yet released API.
 

Latest revision as of 07:56, 27 September 2014

This page describes the API that Sugar Network clients use to interact with a Sugar Network server. See also a guide to basic Sugar Network concepts and its twin page for a technical point of view. In addition, visit the introduction page.

Warning.png
Note
Until announcing API freeze, this document describes the most recent development version of the API.
You can find its implementation on the node-devel.sugarlabs.org server.

Overview

To better understand this API, see a technical explanation of its conceptual level and objects model in particular.

The API operates with Sugar Network resources, which are collections of objects. All objects are identified by globally unique identifiers, GUIDs, and available for operation via basic actions. The API is being provided from a node server or a client. While processing requests, API providers generate events.

The API is RESTful, and is served via HTTP(S) using JSON notation. The common request url format is:

http[s]://SERVER[/RESOURCE[/GUID[/PROPERTY]]][?[cmd=COMMAND][&ARGUMENT=VALUE..]]

When:

  • SERVER, particular Sugar Network API server;
  • RESOURCE, name one of the existing resources;
  • GUID, the RESOURCE's particular object;
  • PROPERTY, particular property of GUID object;
  • COMMAND, optional command name; combination of HTTP request method (GET, POST, PUT, or, DELETE) and [possibly empty] COMMAND composes the requested action;
  • ARGUMENTs and VALUEs depend on the particular action.

In most cases, the server replies in JSON notation. If a request fails, the replied JSON object will contain a request key, with the original request, and error key, with an error message.

API version

Sugar Network nodes might support multiple API versions at once but only one of them is default, i.e., the one which is in use if clients do not specify particular API version. To specify API versions in client request, setup the X-API HTTP header with chosen version. If such header is omitted, default version will be used by the node;

Currently available API versions:

  • 0.1 initial API implementation, should not be used;
  • 0.2 the most recent version, the rest of the document describes exactly this version.

Nodes

These are standard Sugar Network API servers publicly available.

  • node-devel.sugarlabs.org
    Development server which does not contain important data and is free for any experiments (administrative privileges for anonymous users); default API version is 0.2;
  • node-testing.sugarlabs.org
    Recent stable release with regular data import from the production server; is still free for any experiments; default API version is 0.1;

Resources

The following diagram shows the full list of objects implemented by the Sugar Network API.

Sugar Network objects

Property types

Generally, Sugar Network objects' property types correspond to JSON types. The only exceptions mentioned in the following list:

  • enum, is an enumerated type when a value is a string from the predefined list of constants;
  • markdown, is a string formatted in the Markdown syntax;
  • blob, is a file represented by string value which is a SHA-1 digest of file's content; the file itself can be obtained from the GET /blobs/DIGEST request;
  • aggregated, is a list of JSON objects which has special API to treat its items; each aggregated item has a unique identifier; items might be created not only by the object's authors.

Resource.author

A dictionary of authors working on the corresponding resource. Keys are Sugar Network User guids, or, if particular author is not registered in the Sugar Network, full user names. Values are dictionaries with the following keys:

  • name
    Full author's name;
  • role
    An integer which is a bit-wise ORed value of the following constants:
    • 0x1, author is registered in the Sugar Network (and guid key is set);
    • 0x10000, author is the original author of the corresponding resource; if it is not set, user is only a maintainer, e.g., an uploader of a book which has its original authors;
  • avatar
    An url to author's avatar.

Resource.status

This is a system level property which can be set only by node editors. It is a list of "badges" editors set depending on the object quality. Currently supported statuses are:

  • featured, the object is popped up by node editors.

Resource.pins

This property makes sense only for objects provided from a local proxy. The property is intended to store local user's preferences or statuses remote object has in local environment. Currently supported values are:

  • favorite, set if a user has "stared" the object;
  • checkin, applied to Context objects only, set if a user has "pinned" the context to keep its most recent version permanently in the local system;
  • stale, applied to Context objects only, set if previously checked-in Context might have more fresh releases on the node; it is not possible to filter Contexts by this value;
  • inprogress, applied to Context objects only, set if the Context is in the process of downloading content from the node; it is being temporally set before launching the Context or checking it in; it is not possible to filter Contexts by this value.

Context.type

  • activity, Sugar application;
  • book, books in various forms;
  • group, a social group of related activities;
  • talks, sub-type to mix-in offline discussion forum;
  • project, sub-type to mix-in issue tracker and polling functionality.

Context type specifies how context, and all related resources, can be used. For example, activity type assumes activity bundles uploaded to the Context.releases property, or, Post.type depends on Context type it was created for.

Context.releases

Contexts with activity or book types might have releases, i.e., activity or book versions that users can download. The releases property is aggregated where each item describes one particular version. There is no need in working with the releases property directly, there are high-level API commands to upload and download releases.

Post.type

Choose Post types according to Context types the Post belongs to.

  • topic, general purpose discussion; talks Contexts;
  • artefact, object generated by Context application; activity Contexts;
  • issue, problem with the Context; project Contexts;
  • poll, a poll within the Context; project Contexts;
  • post, a comment for a parent Post object; Context type independent.

Post.topic

Only post type Post objects belong to a parent Post which guid should be specified in the topic property. The system design assumes only a two-level Posts hierarchy.

Post.resolution

Post types issue and poll topics might have a resolution to expose the current status. The only way to change topic resolution is creating a dependent post with resolution property set.

Resolutions for issue Post objects:

  • unconfirmed, newly created issue;
  • new, confirmed issue;
  • needinfo, posted information about the issue is insufficient, more details needed;
  • resolved, the issue is resolved, closed;
  • unrelated, the issue does not related to the Context, closed;
  • obsolete, the issue is already solved in recent Context releases, closed;
  • duplicate, the issue is a duplicate, closed.

Resolutions for poll Post objects:

  • open, the poll is open for votes;
  • closed, the poll is closed for votes.

Base API

List of actions common of all API providers.

POST /RESOURCE

Create new resource object.

JSON object keys to send:

  • RESOURCE's properties.

JSON object keys to receive:

  • guid, with globally unique identifier that specifies the created object.
PUT /RESOURCE/GUID

Modify resource object. By default, might be called only by GUID creator.

JSON object keys to send:

  • RESOURCE's properties to modify.
DELETE /RESOURCE/GUID

Delete resource object. Actual object destruction won't happen, the object will be hidden. Garbage collection of hidden objects will be processed by Network administrators. By default, this action may be called only by the GUID creator.

GET /RESOURCE[?offset=INTEGER][&limit=INTEGER][&query=STRING][&reply=PROP][&order_by=[+|-]PROP][&group_by=PROP][&PROP=VALUE][&!PROP=VALUE]

Find resource objects.

Where:

  • offset, int
    start index to return entries from, the default value is 0;
  • limit, int
    do not return more then specified value, maximal and default values are being setup on server side;
  • query, str
    search request in Xapian notation; if property is boolean, integer or datetime, it supports searching by ranges, i.e., PROP:[START]..[END];
  • PROP, str
    supplements query with filtering by exact value of the PROP property; the resulting query string will be PROP=VALUE AND (QUERY); argument is multiple;
  • !PROP, str
    supplements query by excluding exact value of the PROP property; the resulting query string will be NOT PROP=VALUE AND (QUERY); argument is multiple;
  • reply, str
    RESOURCE properties to return; by default, return only guid property; argument is multiple;
  • order_by, str
    property to sort the resulting list by; if starts with the -, the order is descending, otherwise it is ascending;
  • group_by, str
    property name to group resulting list by.

JSON object keys to receive:

  • total, total number in requested query (the reply might contain only the portion restricted by limit request argument);
  • result, an array of dictionaries with resource object properties, dictionaries contain at least guid property.
GET /RESOURCE/GUID[?reply=PROP]

Where:

  • reply, str
    RESOURCE properties to return; by default, return only guid property; argument is multiple;

Return properties for a particular resource object.

JSON object keys to receive:

  • properties that were specified in reply argument(s), at least guid.
PUT /RESOURCE/GUID/PROP

Modify particular resource property. By default, might be called only by GUID creator.

GET /RESOURCE/GUID/PROP

Return property value for particular resource object.

Data to receive:

  • property value in JSON notation for regular properties;
  • raw data or redirection for BLOB properties.

Aggregated properties

Aggregated properties have special API to treat their content.

POST /RESOURCE/GUID/PROP

Submit new item. The command returns an id for newly created aggregated item. Depending on particular property, new items might be created not only by object's authors.

PUT /RESOURCE/GUID/PROP/ID

Update existing aggregated item. Depending on particular property, the command is allowed either to object's authors or to aggregated item submitter.

DELETE /RESOURCE/GUID/PROP/ID

Delete existing aggregated item. Depending on particular property, the command is allowed either to object's authors or to aggregated item submitter.

Notifications

It is possible to subscribe to server events. Notification will happen using HTML5 Server-sent events (SSE).

To start subscription, send the following request:

GET /?cmd=subscribe

Response will be served with text/event-stream MIME type for default SSE message type. SSE message will be a JSONified object with the following, at least, attributes:

  • event
    event type.

Node API

This is an API provided by Sugar Network nodes on top of base one.

Authentication

Right now, the only way to be authenticated on a Sugar Network server is by running a local application on the client side and using the API it provides.

TODO

Authorization

Read-only access is available for anonymous requests, except special content like machine serial numbers. But to process any changes, clients need to be authenticated.

Right after creating any Sugar Network object, its author becomes the only user who can process any object modifications afterwards. Authority information will be kept in the author property and can be modified using the following commands.

PUT /RESOURCE/GUID?cmd=useradd&user=USER&role=ROLE

Add another user who can modify the corresponding object. USER argument should be either User guid (for authors registered in the Sugar Network), or, full author name.

PUT /RESOURCE/GUID?cmd=userdel&user=USER

Remove user from the authority list. It is not possible to remove yourself. USER argument should be either User guid (for authors registered in the Sugar Network), or, full author name.

TODO

Retrieving releases

To easy download Context releases and avoid reading raw Context.releases property, there are special high-level API commands.

GET /context/GUID?cmd=solve[&lsb_id=LSB_ID][&lsb_release=LSB_RELEASE][&assume=DEPENDENCY-VERSION]

The command returns information about what particular releases should be downloaded depending on provided requirements. This command might return not only one release, e.g., activities might have dependencies either system packages or another Sugar Network Contexts.

Solving requirements might be:

  • LSB_ID, if Context releases depend on system packages, specify the LSB distributor id to consider while choosing particular packages;
  • LSB_RELEASE, if Context releases depend on system packages, specify the LSB release number of the distribution to consider while choosing particular packages;
  • DEPENDENCY-VERSION, the assume argument instructs server to assume that specified dependency is already available on client side and should be taken into account while solving; this is especially important for package dependencies when server considers packages available only from official repositories but users might have more recent package versions installed in local system; e.g., the above example request will fail without sugar-0.94 because neither lsb_id nor lsb_release were specified (even if LSB information is passed, server might not have information about what package versions come from official repositories).

The resulting info is a JSON object with keys equal to Context guids and value objects for chosen release with the following keys:

  • blob, bundle digest to download;
  • version, chosen version number;
  • title, the Context.title value;
  • command, a command to launch the bundle, only for Sugar activities.

For example, the GET /context/org.laptop.TurtleArtActivity?cmd=solve&assume=sugar-0.94 request returns:

{
  "org.laptop.TurtleArtActivity": {
    "title": "Turtle Blocks",
    "version": "202",
    "blob": "http://download.sugarlabs.org/activities/4027/turtleblocks-202.xo",
    "content-type": "application/vnd.olpc-sugar",
    "size": 4715955,
    "unpack_size": 12873871,
    "command": "sugar-activity TurtleArtActivity.TurtleArtActivity",
  },
  "sugar": {
    "version": "0.94",
  },
}

Like the solve command, clone makes a solution but returns bundle itself, so, there is no way to get information about possible dependencies.

GET /context/GUID?cmd=clone[&lsb_id=LSB_ID][&lsb_release=LSB_RELEASE][&assume=DEPENDENCY-VERSION]

Upload releases

To easy upload Context releases and avoid writing to raw Context.releases property, there is a special high-level API command.

POST /context?cmd=submit[&PROP=VALUE][&initial]

Where the PROP arguments are optional release properties. The initial argument asks the system to create new Context resource new release will belong to.

The posting data might be two types,

  • Sugar activities in .xo bundles,
    there is no need in PROP arguments, all properties will be populated basing on metadata from a .xo bundle; including release notes from the CHANGELOG file in Markdown notation; besides, only in this case initial makes sense because it is the only way to get Context properties;
  • Arbitrary data,
    all required release properties should be specified in PROP arguments, at least context and version; license should be specified only if there are no existing releases to pickup license from.

Node statistics

The node statistics are about the entire server and depersonalized. Statistics are being collected by analyzing regular requests to an API server and stored for each Sugar Network node. To read such info, call the command:

GET /?cmd=stats[&start=SECONDS][&end=SECONDS][&event=EVENT][&limit=NUMBER]

Where:

  • start and end is a time interval to get statistics for; if omitted, the beginning and the end of entire life cycle will be used;
  • event, multiple argument to specify what stats should be returned; if omitted, return all sources;
  • limit, number of stat records to return for the start-end interval; note that this amount is not precise, the final resultset might be smaller or bigger depending on chosen resolution; stats resolution depends on node configuration, default values are 1 day, 10 days, 30 days, 365 days; if omitted, return end record only.

Possible events are:

  • users, total number of existing User objects;
  • contexts, total number of existing Context objects;
  • released, average number of newly uploaded Context.releases for specified time frame;
  • solved, average number of requested Context solutions for specified time frame; note that this value does not equal to the number of solution usages on client side since solutions might be cached;
  • reported, average number of newly uploaded failure Report objects for specified time frame;
  • topics, total number of top-level Post objects;
  • posts, total number of dependent Post objects.

Client API

The reasons to proxy Sugar Network data on users side:

Proxying happens by providing the same Sugar Network API (with some extra functionality, see below) from local process launched beforehand.

Offline mode

Being connected to a Sugar Network node, local proxy provides original API from the node. If the connection is lost, the proxy will switch to local Sugar Network storage and continue working providing only base API. Any content created in offline mode will be uploaded to the node after getting a connection back.

Besides, local Sugar Network storage will be reused to keep users preferences, such as:

  • Favorited Contexts
    to select preferred Context resources; these Contexts will be marked by favorite value in the Context.layer property;
  • Checked-in Contexts
    to keep most recent Context (for activity and book types) version in local storage to make it available in offline; note that there is no need in checking-in to speedup online lunch, versions are being cached anyway; these Contexts will be marked by checkin value in the Context.layer property.

To control users preferences there are special API commands:

PUT /context/GUID?cmd=favorite

Set favorite status.

DELETE /context/GUID?cmd=favorite

Unset favorite status.

PUT /context/GUID?cmd=checkin[&spawn]

Check-in the specified Context. By default, the command will return streamed text/event-stream MIME type data to monitor the progress. If the spawn argument is specified, the command will exit immediately with asynchronous sending progress events.

DELETE /context/GUID?cmd=checkin

Checkout the Context.

Launching

Sugar Network Contexts (for activity and book types) can be launched as-is. The launching process is implicit and includes selecting the most recent (and appropriate for software contexts) version, downloading bundles from the Sugar Network, installing missed software dependencies, execution itself. All downloaded bundles will be cached [with further garbage collecting] to speedup further launching.

Sugar activities will be directly executed. Book Contexts will be opened in the proper application according to its MIME type.

GET /context/GUID?cmd=launch[&args=ARG][&activity_id=ACTIVITY_ID][&object_id=OBJECT_ID][&uri=URI][&app=APP][&spawn]

Arguments that make sense only for Sugar activities:

  • ARG, command line argument to pass to launched activities, repeat ARG for each argument;
  • ACTIVITY_ID, internal activity id which will be auto set if omitted;
  • OBJECT_ID, Journal object id to resume;
  • URI, URL to resume if activity supports this functionality.

Arguments that make sense only for books:

  • APP, specify application Context to open the book by; if omitted, the system will try to find most appropriate option, among all existing software Contexts.

Common arguments:

  • spawn, by default, the command will return streamed text/event-stream MIME type data to monitor the whole launching process until exiting the application; if the spawn argument is specified, the command will exit immediately with asynchronous sending launching events.

Experimental API

There is no guaranty that the following API will be stated as stable or frozen sometime.

Access to Sugar Journal

It is possible to get access to local Sugar Journal using special, journal, resource provided from client API. This kind of access might be useful when local applications cannot use DBus sugar-datastore API, e.g., Javascript applications. API to Journal is restricted only to read-only access:

GET /journal?offset=INTEGER&limit=INTEGER[&query=STRING][&order_by=[+|-]PROP][&QUERY_PROP=VALUE[&...]]
GET /journal/JOURNAL_ID[?reply=PROP[,..]]
GET /journal/JOURNAL_ID/PROPERTY

Usage

Being HTTP based, Sugar Network API can be used in any manner regular HTTP requests can be handled. But for command-line access, there is a handy tool, sugar-network, which takes care about Sugar Network specific like launching local API (if it is not already available) to get access to local proxy.

The sugar-network command-line format is below. Call sugar-network --help for more detailed info.

sugar-network GET|POST|PUT|DELETE PATH ARG=VALUE [..]
  • PATH, is an url path;
  • ARG=VALUE, request arguments as they being passed to in url.

POST and PUT commands require data to pass, use the following command-line arguments:

  • -f FILE to specify the file to pass;
  • -d DATA to specify string to pass;
  • -j posted data should be encoded into JSON before posting.

Getting involved

  • Submit your bug report or feature request.
  • Browse our implementation discussions, and post your feedback. (You should join this discussion list in order to avoid having your messages postponed for moderation.)