Tag Info

Hot answers tagged

6

There is no theoretical limit to how deep JSON objects can be nested, but there usually is a practical limit based on the decoder being used. For example, PHP's json_decode() has a default limit of 512 levels, though it can be adjusted. Read the documentation for the code using the JSON to determine the max depth. If your JSON is actually hitting depth ...


4

I think you are starting from the wrong end. API design is about what the client/requester requires not about how you represent the data internally. If the client need the category name then just provide it along with the id (if its useful to the client). As a Post belongs to only one category there is no reason to have anything other than a flat structure. ...


3

Structurally, I would reconsider the notion that a post belongs to a category. That's a strange way to model the relationship, especially considering a post very well may form a relationship with multiple categories. So in my mind a post has multiple categories. As @James Anderson initiated, you shouldn't think about your API as a result of your persistence ...


3

404 is perfectly fine for this use case. 4xx status codes are client error codes, so browser treats them as such, and that is perfectly fine too. Another kind of APIs (e.g. JSON-RPC) use different approaches, but since you're going RESTful, do not change response code just to make console output look pretty - it is not a use case, users are not supposed to ...


1

From the comments... if everything else you have is C++ then the best answer is to write it in C++, building a mish-mash of different bits of programming languages is a right PitA to maintain and support. So, if you have C++ and need to resolve XML to JSON, it seems obvious to use the xml2json library that you linked to. It comes with sources so you can ...


1

Should write and read parts be methods in a same class? I would disagree with this because reading and writing are two separate responsibilities and if you want to follow good practices such as Single Responsibility Principle, I would separate them out into two classes. It might seem like an overkill but you will see that with your code growing in the ...


1

While I agree with James, sometimes for whatever reasons you may want to have objects, so as to have a better representation of the actual data. In those cases, there are two considerations: Having just CategoryId, if you laways or almost always need the name, will require another request; Having both options is pretty useless since Post.CategoryId is not ...



Only top voted, non community-wiki answers of a minimum length are eligible