0

My understanding of REST is that anything that does not change state to the underlying system (e.g. query) should be a GET request. This also means that query parameters have to be put into the URI like so:

api/SomeMethod/Parameter1/{P1:double}/Parameter2/{P1:double}

or as query strings as discussed here:

REST API Best practice: How to accept list of parameter values as input

Sometimes the query may require a lengthy vector (number of x/y points). How do I overcome the length problem of URIs here? Should I just use a POST? Thanks.

Community
  • 1
  • 1
cs0815
  • 16,751
  • 45
  • 136
  • 299
  • Are you concerned about the querystring limit? – lbrahim Oct 24 '15 at 11:08
  • yes i am. The limit is about 2000 characters as far as I know. – cs0815 Oct 24 '15 at 11:38
  • According to [this](http://stackoverflow.com/a/812962/1565402) it should be more than that for IIS and also configurable. You can also try and configure it according to your needs : http://forums.asp.net/t/1973616.aspx?Bad+Request+Querystring+Length+exceeds – lbrahim Oct 24 '15 at 16:44

1 Answers1

1

If the vector really is big enough to start worrying about you should really consider moving it out of the query params and represent it as a RESTful resource.

For example, create a collection at:

api/Vector

Then your API clients can POST their large vectors and then in another request refer to it by a single id number.

This reduces the size of the query length drastically, abides by REST, and allows for these vectors to be easily reused. If you are worried about storage you can expire vectors after 30 minutes or longer.

Another option is to go down the JSON-LD road which is similar except you don‘t host the vectors. You just provide an @context object and API clients will host the vector on their own server and reference it to your API by URL in a query parameter.

Calebmer
  • 2,972
  • 6
  • 29
  • 36
  • makes sense but not in my scenario where I want to compare large 'vectors'. example large vector, is there already at least one that is 90% similar ... – cs0815 Oct 25 '15 at 06:54
  • So why not have an endpoint which takes vector 3, vector 4, and returns 80% or something? – Calebmer Oct 25 '15 at 12:13
  • when you say 'take' do you mean POST? the requirement is that one vector is not persisted .... – cs0815 Oct 25 '15 at 12:17