Difference between revisions of "ReST"
From Wiki2
(Created page with "====ReST==== *GET request to /api/users – List all users *GET request to /api/users/1 – List info for user with ID of 1 *POST request to /api/users – Create a new user *...") |
|||
Line 1: | Line 1: | ||
====ReST==== | ====ReST==== | ||
=====setup===== | |||
======Add rewrite rules====== | |||
so a restful path /hsc/feeds/1234 (which doesn't really exist) sends you to the API which processes the request using the /feeds/12345 information from the path. | |||
In /etc/apache2/sites-available/default add rules like | |||
<syntaxhighlight> | |||
<Directory /var/www/hsc> | |||
RewriteEngine On | |||
RewriteRule feed/([0-9]+) /var/www/hsc/index.php?id=$1 | |||
RewriteRule feeds /var/www/hsc/index.php | |||
RewriteRule datastreams /var/www/hsc/index.php?id=$1 | |||
RewriteRule prog /var/www/hsc/index.php?id=$1 | |||
RewriteRule progs /var/www/hsc/index.php?id=$1 | |||
</Directory> | |||
</syntaxhighlight> | |||
The API processing code resides in /hsc in this case. | |||
======when to GET PUT POST====== | |||
:GET when you want some data | |||
:PUT when you've got data to put in the API | |||
:POST when you want to setup something new | |||
:DELETE duh | |||
In the case of home_system_control (hsc): | |||
*GET request to /api/users – List all users | *GET request to /api/users – List all users | ||
*GET request to /api/users/1 – List info for user with ID of 1 | *GET request to /api/users/1 – List info for user with ID of 1 | ||
Line 5: | Line 29: | ||
*PUT request to /api/users/1 – Update user with ID of 1 | *PUT request to /api/users/1 – Update user with ID of 1 | ||
*DELETE request to /api/users/1 – Delete user with ID of 1 | *DELETE request to /api/users/1 – Delete user with ID of 1 | ||
======refs====== | |||
:[https://cosm.com/curl?url=v2%2Ffeeds%2F83080 cosm curl helper] | :[https://cosm.com/curl?url=v2%2Ffeeds%2F83080 cosm curl helper] | ||
:http://api.cosm.com/v2/feeds/83080/datastreams/noise.csv?start=2013-01-11T19:30:00Z&end=2013-01-11T21:00:00Z&interval=0 doesn't work | :http://api.cosm.com/v2/feeds/83080/datastreams/noise.csv?start=2013-01-11T19:30:00Z&end=2013-01-11T21:00:00Z&interval=0 doesn't work |
Revision as of 10:14, 24 January 2013
ReST
setup
Add rewrite rules
so a restful path /hsc/feeds/1234 (which doesn't really exist) sends you to the API which processes the request using the /feeds/12345 information from the path.
In /etc/apache2/sites-available/default add rules like <syntaxhighlight> <Directory /var/www/hsc> RewriteEngine On RewriteRule feed/([0-9]+) /var/www/hsc/index.php?id=$1 RewriteRule feeds /var/www/hsc/index.php RewriteRule datastreams /var/www/hsc/index.php?id=$1 RewriteRule prog /var/www/hsc/index.php?id=$1 RewriteRule progs /var/www/hsc/index.php?id=$1 </Directory> </syntaxhighlight> The API processing code resides in /hsc in this case.
when to GET PUT POST
- GET when you want some data
- PUT when you've got data to put in the API
- POST when you want to setup something new
- DELETE duh
In the case of home_system_control (hsc):
- GET request to /api/users – List all users
- GET request to /api/users/1 – List info for user with ID of 1
- POST request to /api/users – Create a new user
- PUT request to /api/users/1 – Update user with ID of 1
- DELETE request to /api/users/1 – Delete user with ID of 1
refs
- cosm curl helper
- http://api.cosm.com/v2/feeds/83080/datastreams/noise.csv?start=2013-01-11T19:30:00Z&end=2013-01-11T21:00:00Z&interval=0 doesn't work
- http://cosm.github.com/cosm-js/tutorial/
- accessing-incoming-put-data-from-php
- create-a-rest-api-with-php
- http://rest.elkstein.org/2008/02/using-rest-in-php.html
- http://blog.garethj.com/2009/02/17/building-a-restful-web-application-with-php/
- get for my feed
- making-reliable-connections-with-arduino