Skip to content

Instantly share code, notes, and snippets.

@JimBobSquarePants
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimBobSquarePants/c966ca9fd5c48107ab33 to your computer and use it in GitHub Desktop.
Save JimBobSquarePants/c966ca9fd5c48107ab33 to your computer and use it in GitHub Desktop.
Conversation on best api design for complex objects in querystring parameters

What would be the best way to work with complex objects, prevent collision and make them easy to parse.

?watermark={text:"I am the copy",position:[0,0]}&overlay={image:"overlay.jpg",position:[50,50]}

or

?watermark="I am the copy"&watermark.position=0,0&overlay=overlay.jpg&overlay.position:50,50

Advantages of the first approach. Easy to parse using a json parser. e.g Json.NET No chance of collision

Disadvantages of the first approach. Verbose.

Advantages of the second approach. Easy enough to filter via regex.

e.g (overlay=|overlay.\w+=)[^&]+

No chance of collision

Disadvantages of the second approach. Requires individual parsing of matched properties though you could possibly use Json.NET for that also.

Thoughts??

@mortenbock
Copy link

As a consumer of the resizer, I would prefer the second version. I think I would go with dashes though. Seems more query string ish to me.

?watermark-text=I am the copy&watermark-position=0,0&overlay-image=overlay.jpg&overlay-position:50,50

That is much easier to type and edit by hand for people not generating url's from code. If you attempt to write a json parameter by hand, you will be more likely to make syntax errors, forgetting a " or a } or a ].

The above query string scheme will seem familiar to devs used to working with css.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment