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 *...") |
|||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
====ReST==== | ====ReST==== | ||
[http://blog.brunoscopelliti.com/building-a-restful-service-with-angularjs-and-php-backend-setup Angular and PHP] | |||
=====Apache 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 lang="html5"> | |||
<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> | |||
remember to restart apache | |||
/usr/sbin/apache2ctl restart | |||
</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 33: | ||
*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 | ||
Line 14: | Line 43: | ||
:[http://api.cosm.com/v2/feeds/83080 get for my feed] | :[http://api.cosm.com/v2/feeds/83080 get for my feed] | ||
:[http://www.designspark.com/blog/pachube---making-reliable-connections-with-arduino making-reliable-connections-with-arduino] | :[http://www.designspark.com/blog/pachube---making-reliable-connections-with-arduino making-reliable-connections-with-arduino] | ||
Latest revision as of 17:32, 9 April 2014
ReST
Apache 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 lang="html5"> <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> remember to restart apache /usr/sbin/apache2ctl restart </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