Difference between revisions of "ReST"

From Wiki2
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
====ReST====
====ReST====
=====setup=====
[http://blog.brunoscopelliti.com/building-a-restful-service-with-angularjs-and-php-backend-setup Angular and PHP]
=====Apache setup=====
======Add rewrite rules======
======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.  
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
In /etc/apache2/sites-available/default add rules like
<syntaxhighlight>
<syntaxhighlight lang="html5">
<Directory /var/www/hsc>
<Directory /var/www/hsc>
RewriteEngine On
RewriteEngine On
Line 14: Line 15:
RewriteRule progs /var/www/hsc/index.php?id=$1
RewriteRule progs /var/www/hsc/index.php?id=$1
</Directory>
</Directory>
remember to restart apache
/usr/sbin/apache2ctl restart
</syntaxhighlight>
</syntaxhighlight>
The API processing code resides in /hsc in this case.
The API processing code resides in /hsc in this case.
======when to GET PUT POST======
======when to GET PUT POST======
:GET when you want some data
:GET when you want some data
Line 39: 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]
=====websockets=====
:http://code.google.com/p/phpwebsocket/
:[http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ start-using-html5-websockets-today]
:[https://github.com/cosm/cosm-js cosm javascript library] [http://cosm.github.com/cosm-js/ docs]

Latest revision as of 17:32, 9 April 2014

ReST

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/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