Skip to content

[Feature Request] Support pluralized REST resource names #2178

@lsmith77

Description

@lsmith77

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions