herbsjs / herbs2rest

Create a REST API based on HerbsJS
MIT License
2 stars 13 forks source link

Herbarium - Use metadata to customize REST endpoints #28

Closed dalssoft closed 1 year ago

dalssoft commented 2 years ago

Dependency: https://github.com/herbsjs/herbs2rest/issues/22

Being able to customize REST endpoints is extremely important since the current convention is just one of many possible configurations.

But instead of informing the library (herbs2rest) explicitly how to behave, we should use generic metadata to achieve that.

For instance:

Verbs:

herbarium.usecases.get('UpdateUser').metadata({ REST: { verb: 'GET' } })

URL path:

herbarium.usecases.get('UpdateUser').metadata({ REST: { path: '/user/:id/update' } })

Resource:

herbarium.usecases.get('UpdateUser').metadata({ REST: { resourceName: 'users' } })
vitorgamer58 commented 1 year ago

What exactly does the resourceName field refer to?

dalssoft commented 1 year ago

What exactly does the resourceName field refer to?

The resource to be used: GET /{resourceName}/ -> GET /user/

vitorgamer58 commented 1 year ago

What exactly does the resourceName field refer to?

The resource to be used: GET /{resourceName}/ -> GET /user/

Would that make group replacement? Or addition?

For example, I have usecases and routes:

Test endpoints
    GET /Test/ -> ReadAll Usecase
    GET /Test/:id -> Read Usecase
    POST /Test -> Create Usecase
    PUT /Test/:id -> Update Usecase
    DELETE /Test/:id -> Delete Usecase
    OTHER /customgetallroute -> Other Usecase

If I pass the resourcename 'companies' it should look like this: PUT /Test/companies/:id -> Update Usecase Or PUT /companies/:id -> Update Usecase ?

dalssoft commented 1 year ago

Would that make group replacement? Or addition?

If you want to follow the convention {httpVerb} /{resourceName}/:id you can just inform resourceName and a path will be generated for you.

If you want to override the convention, you can inform the path directly. Ex: /user/:id/update/foo/bla.

herbsjs-robot commented 1 year ago

:tada: This issue has been resolved in version 4.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: