4 ms·
`/topic/add` would be a fine URL to return the form HTML, the "RESTful" API would be like `POST /api/topic` where POST implies create and topic implies, well, t
by bryanh 13y ago
`/topic/add` would be a fine URL to return the form HTML, the "RESTful" API would be like `POST /api/topic` where POST implies create and topic implies, well, topic.
- lgas 13y agoOften the best approach is to have e.g. /topics be both the API endpoint and the web endpoint for the collection of topics resource and e.g. /topic/<identifier> be the endpoint for individual topic resources. In both cases the server loads the same data, but if the negotiated content type is text/html then it renders an HTML template with the data and returns a page showing a (probably paginated) topic list along with a form for posting a new topic (possibly hidden and revealed by javascript on a button click, etc). The form would POST to the /topics endpoint which would create the new topic and then return a redirect to the /topic/<identifier>. Another form might also allow replacing existing topics by PUTing to a /topic/<identifier> endpoint. Or via PATCH for use via AJAX. The actual /topic/<identifier> links in both the HTML and JSON views would really be something like /topic/<id> or /topic/<uuid> or /topic/<slug>. Again, if you click on one of the topic links in the HTML view in a browser then when you land on the individual topic link it will also negotiate the text/html content-type and you'll get the topic detail page, etc. If you have pages like "most recent topics" or "trending topics" etc they could be mapped to separate collection resources like /topics/recent, /topics/trending, etc that are just projections of the appropriate subset of the overall collection resource. If the negotiated content-type of any GET request is application/json (or e.g. application/edn) then it returns the API results in the appropriate format. If you follow one of the same links served from the JSON file from your API client, then it will again negotiate application/json and it will get the JSON version the topic detail. The JSON results might be in a format like http://stateless.co/hal_specification.html http://stateless.co/hal_specification.html.