1

I'm trying to much around the Philips Hue API. I got the debug CLIP working just fine. Now I'd like to use this more dynamically, get it purring with Processing.

The problem: I have no idea where to even start formatting that request. According to the API docs, you turn a bulb on or off like this:

Address: http://<bridge ip address>/api/newdeveloper/lights/1/state
Body: {"on":false}
Method: PUT

Okay, so I get the address part. But how do I format the Body into the URL? And how I establish that this is a PUT request?

GilloD
  • 561
  • 2
  • 6
  • 18

2 Answers2

2

You don’t format the body into the URL; the body and the URL are quite separate.

Here’s what an HTTP request looks like:

METHOD /path HTTP/1.x
Some: Headers
Foo: Bar

The body

One for this page might look something like

GET /questions/18819266/how-to-parse-a-restful-url HTTP/1.1
Accept: */*
Host: stackoverflow.com
User-Agent: Firefox 23 and somesuch

So to send your example request with curl, it would be something like:

$ curl -v 'http:///api/newdeveloper/lights/1/state' -X PUT --data-binary '{"on":false}'
Ry-
  • 218,210
  • 55
  • 464
  • 476
1

To expand on minitech's answer, data can be sent by HTTP methods such as PUT, DELETE, POST, and GET. If you're trying to "format a url" with data that is meant to be sent, i.e. generating a URL based on parameters you would like to send to Hue, you are actually using GET and not PUT or POST.

Unfortunately, DELETE and PUT are not able to be sent through normal HTML forms via "method", only POST and GET. Depending on what language you're using, you'll need to use LWP or curl or find some other way to send PUT data. Hue's clip.html uses javascript and XMLHttpRequest() if javascript is your preferred programming language.

WindedHero
  • 185
  • 7