Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am finding myself building up a whole bunch of JSON calls all through my application, which are basically actions spread across various controllers. I am considering creating a JSON Controller to keep all the JSON actions in one controller, so instead of;

Products/GetListJSON

I would call

JSON/Products

Might this have ramifications that I haven't considered? Can anyone think of any compelling reasons not to do this?

share|improve this question
    
Is it possible that perhaps most of these JSON calls are similar so perhaps they can be optimised, rather than their location? –  Daniel Hollinrake Jan 14 at 16:36

1 Answer 1

up vote 2 down vote accepted

Rule 1. Cool URI's Never Change. http://www.w3.org/Provider/Style/URI

Do NOT set your resource paths based on programming "optimizations" like this. Design your paths correctly irrespective of coding considerations. The path lives forever. Your code will come and go.

Having the data type ("JSON" in your case) part of the path is frowned upon by some. They argue that the response type should not be part of the RESTful path to the object.

They argue that the response type should be encoded in a header (Accepts, specifically) and the path should be unchanged.

You can, for example, do things like this to achieve the same goal: unchanging URI with encoding not in the path.

/Products/?response=JSON

I don't totally agree with their logic.

But, what's important is that programming language considerations do not drive path design for web services requests.

I think that /Products.json is not bad RESTful design.

I've used the /path/to/json/resource technique in a couple of different forms.

The thing you need to be absolutely clear on is rule #1: Cool URI's don't change because of programming language or toolset considerations.

share|improve this answer
    
Excellent answer sir! –  Daniel Hollinrake Jan 14 at 16:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.