1

This might seem dirty but it's for documentation purposes I swear!

I am accessing my services using GETs in my documentation so people can try things out without needing to get too complicated.

Appending x-http-method-override=POST to the URL forces the server to take a GET as a POST

This is all good except when I need to POST an array of objects. This would be simple in a standard POST but today I have a new bread of nightmare.

The expected POST looks like:

{"name":"String","slug":"String","start":"String","end":"String","id":"String","artists":[{"id":"String","name":"String","slug":"String"}],"locationId":"String"}

As you can see there is an array of artists up in here.

I have tried to do the following:

model/listing?start=10:10&end=12:30&artists[0].name=wayne&artists[0].id=artists-289&locationid=locations-641&x-http-method-override=POST

But to no avail.

How can I get an array of objects into a URL so that service stack will be happy with it?!

I appreciate this is not the done thing but it's making explaining my end points infinitely easier with clickable example URLs

5
  • 2
    C'mon, stop abusing REST. Seems like you trying to use POST by means of GET. No wonder you having troubles. Guess what? It's just the beginning - think about support, API maturity, bewildered users. If I were you, I would stop right there and start using POST. The users of your API have hands and are hopefully intelligent, despite the fact it may sound silly. They will be able to craft a simple POST request. You can also help them by providing a simple and working example. Commented Feb 20, 2014 at 13:29
  • 3
    I did say this was purely for documentation!! this has nothing to do with production code and end users! This has nothing to do with REST purity and extreme REST opinions and religious beliefs. My REST service can behave perfectly RESTful and I can document it how I want. Using a legit question to prove how REST pure you are is a bit cheap IMO Commented Feb 20, 2014 at 14:57
  • I am referring to HTTP RFC standard. Where I agree we can debate about the purity of REST (and let's leave it along), you don't want to violate the standard. That was my point - a common standard that everyone understand. Commented Feb 20, 2014 at 18:42
  • Just to put this out there as an alternative approach to documentation: ServiceStack also supports Swagger, an HTML/JS interface, for interactive documentation of your API. Commented Feb 20, 2014 at 20:34
  • I have tried getting swagger set up but can't figure how to get it to see my api Commented Feb 21, 2014 at 8:06

1 Answer 1

2

You can use JSV to encode complex objects in the URL. This should work for your DTO:

model/listing?name=wayne&artists=[{id:artists-289,name:sample1},{id:artists-290,name:sample2}]&locationId=locations-641

You can programmatically create JSV from an arbitrary object using the ToJsv extension method in ServiceStack.Text.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.