RESTful API – Designing sub-resources

Both approaches can be considered RESTful, provided you do not break the REST constraints defined in the chapter 5 of Roy Thomas Fielding’s dissertation: Client-server Stateless Cache Uniform interface Layered system Code-on-demand I cannot see major pitfalls in both approaches, but I would prefer the Approach B over the Approach A: the URLs are shorter, … Read more

How to handle hierarchical routes in ASP.NET Web API?

Configure the routes as below. The {param} is optional (use if you need): routes.MapHttpRoute( name: “childapi”, routeTemplate: “api/Parent/{id}/Child/{param}”, defaults: new { controller = “Child”, param = RouteParameter.Optional } ); routes.MapHttpRoute( name: “DefaultApi”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional } ); Then call the child APi as /api/Parent/1/child The parent can be called simple … Read more

Spring MVC Controller: Redirect without parameters being added to my url

In Spring 3.1 a preferred way to control this behaviour is to add a RedirectAttributes parameter to your method: @RequestMapping(“save/”) public String doSave(…, RedirectAttributes ra) { … return “redirect:/success/”; } It disables addition of attributes by default and allows you to control which attributes to add explicitly. In previous versions of Spring it was more … Read more

RESTful POSTS, do you POST objects to the singular or plural Uri?

Since POST is an “append” operation, it might be more Englishy to POST to /products, as you’d be appending a new product to the existing list of products. As long as you’ve standardized on something within your API, I think that’s good enough. Since REST APIs should be hypertext-driven, the URI is relatively inconsequential anyway. … Read more

Proper route for checking resource existence in a RESTful API [closed]

HEAD is the most effecient for existence checks: HEAD /users/{username} Request a user’s path, and return a 200 if they exist, or a 404 if they don’t. Mind you, you probably don’t want to be exposing endpoints that check email addresses. It opens a security and privacy hole. Usernames that are already publicly displayed around … Read more

Confusion Between Noun vs. Verb in Rest URLs

Some snippets from the REST API Design Rulebook about different resource types: Document A document resource is a singular concept that is akin to an object instance or database record. Example: http://api.soccer.restapi.org/leagues/seattle/teams/trebuchet Collection A collection resource is a server-managed directory of resources. Clients may propose new resources to be added to a collection. However, it … Read more

How to add method description in Swagger UI in WebAPI Application

This is well documented in the project: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#include-descriptions-from-xml-comments Include Descriptions from XML Comments To enhance the generated docs with human-friendly descriptions, you can annotate controller actions and models with Xml Comments and configure Swashbuckle to incorporate those comments into the outputted Swagger JSON: 1 – Open the Properties dialog for your project, click the “Build” … Read more