-
-
Notifications
You must be signed in to change notification settings - Fork 126
Closed
Description
Is your feature request related to a problem? Please describe.
It is a common pattern to have a model user exposed as /users and /users/123, ie. the URL to the collection is the pluralized model name.
Describe the solution you'd like
Some way to define a mapping or automatic pluralization for the purposes of all exposed URLs via the RestHandler (also including the openapi plugin).
As discussed via Discord at least for v2 we will use a mapping:
https://discord.com/channels/1035538056146595961/1390310045031464981
I thinking maybe we can make a smaller change, without introducing a zmodel attribute. Instead, just pass a mapping at runtime when creating the api handler:
handler: RestApiHandler({
endpoint: ...,
modelNameMapping: { user: 'users', ... }
})
The mapping is simply used right before passing the call to the underlying prismaclient
Something like
let match = this.urlPatterns.single.match(path);
const prismaModel = this.lookupMappedModelName(match.type);
return await this.processSingleRead(prisma, prismaModel, match.id, query);
Describe alternatives you've considered
Accepting the current status quo, ie. either using /user or pluralizing the model name from User to Users.
Additional context
https://restfulapi.net/resource-naming/
Metadata
Metadata
Assignees
Labels
No labels