0

I have a HTTP REST api wanting to wrap a underlying datasource(can be RDBMS like mysql or something else, like HBase). I want to construct an REST API and wrap the underlying implementation, so my API might look like:

http://${APIServer}/${TableName}?attrs=A,B,C&${json_payload}

The payload looks like:

{
    "like": {
        "name": "kev"
    },
    "equal": {
        "id": "2",
        "sex": "male"
    }
}

To achieve something like:

select A,B,C from TableName where name=shengjie and address like %Ireland%

I want to wrap the WHERE conditions into the json_paylaod, is there any best practice for this?

Shengjie
  • 12,336
  • 29
  • 98
  • 139
  • 2
    What backend tech are you using to route and parse the request into SQL? NodeJS? Rails? One note is if you're going to make such a direct connection between your end point and your query be very very careful to avoid SQL injection. – George Yates Aug 15 '13 at 05:50
  • my backend in this case is HBase, so it doesn't have SQL injection issue. But hey, it is a good point :) – Shengjie Aug 15 '13 at 05:52
  • Ha, didn't read your question well enough. I'm not familiar enough with HBase to talk best practices, hopefully someone else can help you out! – George Yates Aug 15 '13 at 05:54
  • it's probably less related to the backend, it is more like REST API best practice to take a json payload. – Shengjie Aug 15 '13 at 05:55
  • 1
    Well I can say you're not likely going to want to include JSON in your URL as you're [limited to ~2000 characters](http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers) so you're probably going to want to POST any JSON in your request body. At that point, it'll make sense to have all your parameters in the JSON you send and have your backend route using the URL to something that can parse the request body into a viable query. – George Yates Aug 15 '13 at 06:00
  • In my case, it's a GET call wanting to take the JSON input. – Shengjie Aug 15 '13 at 06:07

0 Answers0