{"id":892,"date":"2014-05-03T07:55:12","date_gmt":"2014-05-03T07:55:12","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/orion\/?p=892"},"modified":"2015-04-03T07:57:07","modified_gmt":"2015-04-03T07:57:07","slug":"rest-api","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/orion\/uncategorized\/rest-api\/","title":{"rendered":"REST API"},"content":{"rendered":"<p>LeapIn.it uses a REST endpoint for access to the database. This is a design pattern for hypermedia systems, which advocates providing individual resources (e.g., people) with unique URLs, and using those URLs to exchange structured information. HTTP requests can be made to these URLs, where HTTP methods are used to instruct what should happen with attached data, and status codes in responses are used to signal what happened with the data.<\/p>\n<p>The following URL&#8217;s are available:<\/p>\n<p>Requests are in JSON<\/p>\n<table>\n<tbody>\n<tr>\n<th>URL<\/th>\n<th>Method<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/auth<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>POST<\/code><\/td>\n<td>authenticate a user<\/td>\n<td>\n<div><code>201<\/code> &#8220;person with username and password hash have been found&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person and a token<\/p>\n<div><code>401<\/code> &#8220;username or password not found&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/auth\/user<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get the person who is logged in<\/td>\n<td>\n<div><code>200<\/code> &#8220;person is logged in&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person<\/p>\n<div><code>404<\/code> &#8220;no person is logged in&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>DELETE<\/code> (params: token)<\/td>\n<td>delete the session (log out)<\/td>\n<td>\n<div><code>204<\/code> &#8220;session has been deleted&#8221;<\/div>\n<div><code>404<\/code> &#8220;no session exists&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/person<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>POST<\/code><\/td>\n<td>create a person<\/td>\n<td>\n<div><code>201<\/code> &#8220;person created&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person<\/p>\n<div><code>401<\/code> &#8220;username already exists&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/person\/:id<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get a person<\/td>\n<td>\n<div><code>200<\/code> &#8220;person exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>PUT<\/code> (params: token)<\/td>\n<td>modify the person<\/td>\n<td>\n<div><code>200<\/code> &#8220;person modified&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person<\/p>\n<div><code>401<\/code> &#8220;not allowed to modify this person&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>DELETE<\/code> (params: token)<\/td>\n<td>delete the person<\/td>\n<td>\n<div><code>204<\/code> &#8220;person has been deleted&#8221;<\/div>\n<div><code>401<\/code> &#8220;not allowed to delete this person&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/person\/:id\/friend\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get a person&#8217;s friend list<\/td>\n<td>\n<div><code>200<\/code> &#8220;person exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person&#8217;s friend list<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s friend list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>POST<\/code> (params: token)<\/td>\n<td>add a new friend to this person<\/td>\n<td>\n<div><code>201<\/code> &#8220;friend added&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the new friend<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s friend list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>DELETE<\/code> (params: token)<\/td>\n<td>delete a friend<\/td>\n<td>\n<div><code>204<\/code> &#8220;friend removed&#8221;<\/div>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s friend list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/person\/:id\/block\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get a person&#8217;s block list<\/td>\n<td>\n<div><code>200<\/code> &#8220;person exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person&#8217;s block list<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s block list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>POST<\/code> (params: token)<\/td>\n<td>add a new blocked person to this person<\/td>\n<td>\n<div><code>201<\/code> &#8220;blocked person added&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the new blocked person<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s block list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>DELETE<\/code> (params: token)<\/td>\n<td>remove a blocked person<\/td>\n<td>\n<div><code>204<\/code> &#8220;blocked person removed&#8221;<\/div>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s block list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/person\/:id\/room\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get a person&#8217;s room list<\/td>\n<td>\n<div><code>200<\/code> &#8220;person exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the person&#8217;s room list<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s room list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>DELETE<\/code> (params: token)<\/td>\n<td>delete a room from a person&#8217;s room list<\/td>\n<td>\n<div><code>204<\/code> &#8220;room has been removed from person&#8217;s room list&#8221;<\/div>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s room list&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/person\/:id\/feed\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get a person&#8217;s feed<\/td>\n<td>\n<div><code>200<\/code> &#8220;person exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">list of posts in person&#8217;s feed<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this person&#8217;s feed&#8221;<\/div>\n<div><code>404<\/code> &#8220;person does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/room\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token, code)<\/td>\n<td>get a room from a specified code and add it to user&#8217;s room list<\/td>\n<td>\n<div><code>200<\/code> &#8220;room exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the room<\/p>\n<div><code>201<\/code> &#8220;room does not exists, so it has been created&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the room<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/room\/:id\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get a room<\/td>\n<td>\n<div><code>200<\/code> &#8220;room exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the room<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this room&#8221;<\/div>\n<div><code>404<\/code> &#8220;room does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>PUT<\/code> (params: token)<\/td>\n<td>change the name of a room<\/td>\n<td>\n<div><code>200<\/code> &#8220;room exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the room<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this room&#8221;<\/div>\n<div><code>404<\/code> &#8220;room does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/room\/:id\/post\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get the posts in a room<\/td>\n<td>\n<div><code>200<\/code> &#8220;room exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the posts<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this room&#8221;<\/div>\n<div><code>404<\/code> &#8220;room does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>POST<\/code> (params: token)<\/td>\n<td>create a post in a room<\/td>\n<td>\n<div><code>201<\/code> &#8220;post created&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the post<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this room&#8221;<\/div>\n<div><code>404<\/code> &#8220;room does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/room\/:id\/post\/:id\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token)<\/td>\n<td>get a post belonging to a room<\/td>\n<td>\n<div><code>200<\/code> &#8220;post exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the post<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this post&#8221;<\/div>\n<div><code>404<\/code> &#8220;post does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/room\/:id\/post\/:id\/data\/<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token, preview, size, cell)<\/td>\n<td>get the data (or a preview) attached to a post (eg, a picture)<\/td>\n<td>\n<div><code>200<\/code> &#8220;data exists&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the data or a preview<\/p>\n<div><code>401<\/code> &#8220;not allowed to see this post&#8221;<\/div>\n<div><code>404<\/code> &#8220;post does not exist&#8221;<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\"><code style=\"font-weight: bold;\">\/api\/blankcell<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>GET<\/code> (params: token, size)<\/td>\n<td>generate a blank cell<\/td>\n<td>\n<div><code>200<\/code> &#8220;ok&#8221;<\/div>\n<p style=\"margin-left: 10px;\">the blank cell<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>LeapIn.it uses a REST endpoint for access to the database. This is a design pattern for hypermedia systems, which advocates providing individual resources (e.g., people) with unique URLs, and using those URLs to exchange structured information. HTTP requests can be made to these URLs, where HTTP methods are used to instruct what should happen with attached data, and status codes&#8230;<span class=\"path-read-more\"><a class=\"more-link\" href=\"https:\/\/blog.soton.ac.uk\/orion\/uncategorized\/rest-api\/\" title=\"REST API\">  Read more &rarr; <\/a><\/span><\/p>\n","protected":false},"author":94019,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-892","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/posts\/892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/users\/94019"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/comments?post=892"}],"version-history":[{"count":1,"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/posts\/892\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/posts\/892\/revisions\/893"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/media?parent=892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/categories?post=892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/orion\/wp-json\/wp\/v2\/tags?post=892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}