You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for custom API Urls for exposed models #236
Nice feature would be possibility to rewrite default urls of main and related models.
Example:
for main models like
/api/accessTokens to /api/access-tokens
or for related models like
/api/users/{id}/bankAccount to /api/users/{id}/bank-account
There should be setting like url for a model in models.json and also as a paramater options when creating or extending a model. There is option in models.json config called plurals, but would be good to have separate settings to set custom url for model/related models and endpoints ( custom routing ).
Actually, you can already do that, i am pretty sure, it's just not documented too much Change the plurals of the models and you're good, or use the js api, as it follows:
loopback.remoteMethod(Location.nearby,{description: 'Find nearby locations around the geo point',accepts: [{arg: 'here',type: 'GeoPoint',required: true,description: 'geo location (lat & lng)'},{arg: 'page',type: 'Number',description: 'number of pages (page size=10)'},{arg: 'max',type: 'Number',description: 'max distance in miles'}],returns: {arg: 'locations',root: true},http: {verb: 'POST',path: '/nearby'}});
The reason, i presume for not having this feature implemented is because in any real world scenario, you need some sort of consistency, and this is actually the best way of having something that makes sense /products/id/orders makes a lot of sense to me, but anyway, maybe i am wrong. I guess you could alter/override the http property of the desired method, but i would not see that as the best way to obtain consistency.
Plurals for relations doesn't work, only for main model configuration in models.json. I would like to use hyphens instead camel case.
Ritch said that base urls will be probably supported in version 2.0.
Activity
pennycoders commentedon Apr 15, 2014
Actually, you can already do that, i am pretty sure, it's just not documented too much Change the plurals of the models and you're good, or use the js api, as it follows:
Please check this url for more details.
The reason, i presume for not having this feature implemented is because in any real world scenario, you need some sort of consistency, and this is actually the best way of having something that makes sense /products/id/orders makes a lot of sense to me, but anyway, maybe i am wrong. I guess you could alter/override the http property of the desired method, but i would not see that as the best way to obtain consistency.
ariskemper commentedon Apr 16, 2014
Plurals for relations doesn't work, only for main model configuration in models.json. I would like to use hyphens instead camel case.
Ritch said that base urls will be probably supported in version 2.0.
raymondfeng commentedon Apr 18, 2014
The relation name can be customized as follows:
The 'as' property denotes the relation name.
Please note that hyphen might cause problems for JS method names.
Check out:
http://strongloop.com/strongblog/defining-and-mapping-data-relations-with-loopback-connected-models/
fabien commentedon Aug 23, 2014
See also: #433 and strongloop/strong-remoting#90
superkhau commentedon Feb 26, 2015
@raymondfeng @fabien Safe to close?
superkhau commentedon Feb 4, 2016
I am closing this since the feature is already there. @ariskemper Please open a new issue if you are still running into problems.