New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not generate "/edit" route during API generation #1562

Open
hubyhuby opened this Issue Feb 3, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@hubyhuby
Copy link

hubyhuby commented Feb 3, 2019

Description

When generating a project with "--api" you get a route an /edit route for each ressource.
While this make sens for HTML-default mode (without --api), in API mode this doesn t seem to be logical.
In HTML mode the edit route pulls the form with the previous recorded datas to midify.
Then the form will "PUT" the data to update this record.
With API mode you usally handle this "edit" part on your front end and then call directely the PUT / Update API route.

Example of routes :

GET | /chats | | chatsPath | generatedApps/tst2/actions.ChatsResource.List
POST | /chats | | chatsPath | generatedApps/tst2/actions.ChatsResource.Create
GET | /chats/new | | newChatsPath | generatedApps/tst2/actions.ChatsResource.New
PUT | /chats/{chat_id} | | chatPath | generatedApps/tst2/actions.ChatsResource.Update
DELETE | /chats/{chat_id} | | chatPath | generatedApps/tst2/actions.ChatsResource.Destroy
GET | /chats/{chat_id} | | chatPath | generatedApps/tst2/actions.ChatsResource.Show
GET | /chats/{chat_id}/edit | | editChatPath | generatedApps/tst2/actions.ChatsResource.Edit

Expected Behavior

In API mode the "/Edit" route is not required, and shall not be produced. Limitating the surface of the API.

Info

Buffalo Version

v0.12.4

Go Version

go version go1.10.4 linux/amd64

@markbates

This comment has been minimized.

Copy link
Member

markbates commented Feb 3, 2019

This isn't as straightforward as it appears. It could introduce breaking changes and will need to be investigated further.

The Resource interface currently requires both New and Edit functions. The BaseResource provides no-op implementations of all of the Resource methods. The router then builds routes for each of the methods in the interface.

So in order to not generate routes for Edit and New we would need to make considerable changes to the Resource interface, the BaseResource type, and the router.

I'm not saying this can't be done, but it requires a decent amount of thought and planning before it can be implemented, as it has the potential to be a breaking change.

I consider this to be out of scope for the v0.14.0 release, but could, potentially, be included in a v0.15 release.

@markbates markbates added this to the v0.14.x milestone Feb 14, 2019

@markbates markbates self-assigned this Feb 14, 2019

markbates added a commit that referenced this issue Feb 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment