fragmenta / fragmenta-cms

A user-friendly CMS written in Go (golang)
http://fragmenta.eu
MIT License
586 stars 70 forks source link

Incorrect REST API #18

Closed SebastianPozoga closed 8 years ago

SebastianPozoga commented 8 years ago

I want to use rest api for angular2. I founded description like Standard REST handlers for .... in a code.

// Standard REST handlers for tags
r.Add("/tags", tagactions.HandleIndex)
r.Add("/tags/create", tagactions.HandleCreateShow)
r.Add("/tags/create", tagactions.HandleCreate).Post()
r.Add("/tags/{id:[0-9]+}/update", tagactions.HandleUpdateShow)
r.Add("/tags/{id:[0-9]+}/update", tagactions.HandleUpdate).Post()
r.Add("/tags/{id:[0-9]+}/destroy", tagactions.HandleDestroy).Post()
r.Add("/tags/{id:[0-9]+}", tagactions.HandleShow)

But it serve only HTML content only (I tried add "Accept: application/json" to request header) Structure like .../update (it should be http insert) Structure like .../destroy (it should be http delete)

It is incorrect REST / or it is not REST API. Rest standard describe resource mapping and roles of all queries methods.

kennygrant commented 8 years ago

Thanks for filing the issue. It should be possible to serve json (I've done it myself), but you'd need a json template and the json header, otherwise it should work, let me know if you have issues doing that specifically what the issues are. You can render content yourself you don't have to use view.Render(), but again happy to adjust view.Render if required to fix any issues.

Re REST I should have said REST-ish if I've used that term anywhere :) It will probably never be fully REST but I'm happy to consider changes to methods etc if they have a practical application. True Rest would have two urls, no update method at all I think, and use http methods to distinguish intent. REST specifies the HTTP method, not the method name in the app, so for example I believe it is supposed to be:

Historically browser and server library support for the verbs apart from GET and POST has been patchy, hence we still use POST for delete, not true rest. However, this is complete separate from the action names used to define the actions, which is entirely arbitrary (for example rails uses /edit for update). I haven't looked into browser support recently but would be open to looking at changing the urls for resources if it is fully supported in all possible clients for both html and js. Unfortunately I don't think that's the case. See this stackoverflow question for detail on this:

https://stackoverflow.com/questions/165779/are-the-put-delete-head-etc-methods-available-in-most-web-browsers

As far as I know it is still not part of the html standard for forms, which means we can't use it.

There are other frameworks available if you just want to serve only json in a REST style, so it might also be worth looking at them too, as the focus of fragmenta is more on serving html. I would like it to handle json though so please do file bugs on any specific problems you encounter.

SebastianPozoga commented 8 years ago

as you wrote, it is not rest api. It serve a html webpage. The description is incorrect.

kennygrant commented 8 years ago

REST doesn't care what sort of resources are served, so this is nothing to do with json/html.

I'm closing this now as I don't see any constructive criticism but if you have any specific problems with serving json, do put them here. I'll probably change the comment at some point, it's not a high priority.