Confused about idempotency, PUT, GET, POST, etc
Most of the discussions about these topics are about how to form a URL or how to request a resource. Let me describe what I'm doing and see if the community can help me restate my problem in the more web-design-professional language :-)
I'm building a piece of hardware that I suppose you'd call a "web appliance". Similar to an online weather station, it will sit on a home LAN and send messages to a remote server. Let's say that every 5 minutes it wi开发者_高级运维ll send a record of:
timestamp
temperature reading
unit ID #
The "web page in the sky" that is collecting this data is a Ruby-on-Rails app containing tables for device ID's and samples.
I want the web appliance to be able to directly post new samples to the "samples" data table by composing an URL similar to the following:
http://kevinswebsite.com/samples/new?timestamp=2011_Oct_01_1440&unit_id=75&temp=75.5
The above should create a record that at 2:40PMon October 1, 2011, Unit #75 reported a temperature of 75.5 degrees.
Is something like this possible?
Thanks,
Kevin
You should use the GET only to retrieve information in a safe and idempotent way! Looks like your URL is using GET and you want to create corresponding record in your database. I would recommend using POST instead. Please note that POST is not safe and idempotent method. Once you process the POST request, you can create a new record in your table for your new information that you obtain from your web appliance.
That way you can be sure the clients will count on your methods such as GET, POST, DELETE, HEAD, PUT, etc.
Good luck.
精彩评论