Loopback: Alternatives for plural model names in endpoint URLs

Created on 27 Nov 2015  路  7Comments  路  Source: strongloop/loopback

At the moment, LoopBack uses plural form of model name to build the URL where the model is exposed (e.g. Car -> /cars, Person -> /people).

This is a potential issue for non-English developers. For example, plural form of Person may be not obvious for everybody. Furthermore, to support localised (non-English) model names, LoopBack would have to ship with dictionaries for all languages.

Possible solutions proposed by @Setogit:

  • Can we simply remove the "plural feature" altogether with no side effects? For example, if we use singular form instead of plural, is any confusion or property name collision incurred?
  • Or, can we come up with a more mechanical rule so that we don't need dictionary and super clear for global developers.

/cc @strongloop/loopback-devs

feature major

Most helpful comment

For completeness, there are already several possible ways how to customize Model's root path:

I think the question then is what should be default - singular or plural?

On the other hand, considering that the next major version of LoopBack is going to use a different approach to building REST APIs (data models are decoupled from the HTTP API layer, the API is defined via Controllers which have full control over all aspects), I think it makes very little sense to go through the pain of changing the default model path in the current codebase, and this issue should be closed.

All 7 comments

I'm cool to use the model name by default and provide a way to customize it.

+1 for use whatever they define as the model name and provide a way to customize it

I think there will be side-effects, though. Most resources should conceptually be regarded as plural.

What's wrong with just using the manually set plural as before? The only part I don't really like right now is that this plural value is used directly for the url.

I would much prefer a new option urlPrefix or similar to control this, and in case it's omitted, it should fall back to pluralName as before. This would also allow multi-segment prefixes like: /api/things/cars.

Perhaps we should even allow syntax like: /(cars|voitures|whatever) to match different versions (though I would personally be hesitant to take localization this far).

I agree with @fabien in that the concept of plural should exist. This way the convention of /pluralobject/{id} maintains the expected hierarchy of List -> Single Object

I am relatively new to loopback but there is an option to manually provide a value for "plural". Doesn't this allow the user to tailor the API naming to their liking?

I m not able to access different models with same plurals but each having different endpoints ?

my-model.js with /{version}/user/my-model/ and your-model.js with /{version}/user/your-model/

I m also not able to access invoke different remoteMethods in same model like this

my-model.js with /{version}/user/ and your-model.js with /{version}/user/your-model/

method is GET

I too, like the original poster, would like a way to let the developers decide if the endpoints should be plural or singular.

In our case, the singular form is desired.

For completeness, there are already several possible ways how to customize Model's root path:

I think the question then is what should be default - singular or plural?

On the other hand, considering that the next major version of LoopBack is going to use a different approach to building REST APIs (data models are decoupled from the HTTP API layer, the API is defined via Controllers which have full control over all aspects), I think it makes very little sense to go through the pain of changing the default model path in the current codebase, and this issue should be closed.

Was this page helpful?
0 / 5 - 0 ratings