Search code examples
restphilips-hue

How to parse a RESTful URL


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?


Solution

  • 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}'