New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote methods mapping in JSON #209
Comments
Your proposal is aligned with the direction to make it possible to describe the remote methods using json. One idea is to have a routes.json to map http reqs (verb, url, content-type/accept) to nodejs methods. |
👍 thanks. Wold be helpful feature. As well as UI for simplifying this configs definition as a step after all configuration options will be available in json. I can clearly see how this solution will overcome parse.com and other MBAAS with such roadmap. |
@nikita-leonov (and anyone else reading)... proposals / drafts for a routes.js spec are very much welcomed. We are happy to take contributions 😄 |
I would recommend to piggyback on existing solution instead of inventing some new standard. This is healthy for product, third-party community support and moving complete industry forward. I know four solutions that could be somehow used for definition of resources mapping and :
I really like RAML. It is modular, extendable and so on. Current approach with json is really limiting as we forced to define everything within one json file. On a big APIs current approach will become a mess. Also Masher iodocs could be a nice option from a business development standpoint for strongloop and loopback. IODocs is weaker form a technology point of view as it is not a standard, it is a tool like swagger but with own specification of mappings for methods and resources. But at least they have all use cases covered. Btw currently swagger do not shop remote methods, so could be an option to solve multiple tasks at once — get specification for a mapping, get right tool for self-documented APIs and build relationship with Mashery. |
One more item in favor of RAML they have JavaScript based parser implemented — https://github.com/raml-org/raml-js-parser It capable for running in node.js. |
Thanks for the ideas. We have been exploring most of them. Swagger is currently used for the API explorer. There are probably a few layers in play:
Ideally, we should be able to declare/derive the metadata declaratively or programatically. Item 2 is more tied to the JS method, some sort of annotations should work. Item 3 could be further decoupled. |
Agree regarding data models. Not all the standards cover this. For example RAML is more API oriented rather than resources / models oriented specification. That is why I provided WRML as a reference as there work ongoing on defining APIs by using resources terms which is more in line with your current approach. I will think a little bit more about this task in direction of leveraging existing technologies and standards. It is much harder to invent and develop something new, rather than leverage existing functionality. I strongly believe that there is technology available that will fit the goal. |
@altsang @raymondfeng @bajtos and I discussed this a bit. Points in our discussion:
|
fwiw I'm doing something like this in my own setup by using the unimplemented eg common/models/my-model.json
common/models/my-model.js:
Seems to be working ok so far. My only gripe with it is that the remoteMethod call expects documentation for the properties to be in a Would be great to have some support like this in loopback itself. |
@mrfelton can you submit a pull request with your implementation? Remote methods should be defined by registry.createModel. Few things to change in the second snippet:
The "doc" keyword is deprecated, you should use "description" in your model definitions too. See Model definitions JSON file docs. |
Thanks @bajtos .
The reason I wait until the model is attached is because I needed access to the app object so that I can inspect the structure and pull out the method details from there. I wasn't able to get a handle on a complete enough app object anywhere else. I'm guessing that if I move it to
I'm not sure what you mean by ping and pong. Any docs on that you can point me towards?
Awesome! |
They are just example method names. "ping" is a static method, "pong" is a prototype (instance) method. The code sample in your comment above requires developers to register them in this way: remoteMethods: {
"ping": { isStatic: true, /*...*/ },
"pong": { isStatic: false, /*...*/ }
} What I would like to see instead: remoteMethods: {
"ping": { /*...*/ },
"prototype.pong": { /*...*/ }
} Does it make sense now? |
gotcha. I read through #597 that you linked to also so it makes more since to me now. I actually hadn't come across the isStatic property before. |
…rongloop#209 Signed-off-by: Tom Kirkpatrick <tom@systemseed.com>
…e added to the model strongloop#209 Signed-off-by: Tom Kirkpatrick <tom@systemseed.com>
Would be nice to have an option to define remote methods mapping to an actual classes in JSON. So we will have complete REST interface defined in one place with a logic and complex cases in JS. I do not see why some of such constructions could not be a part of JSON mapping:
ApplicationModel.authenticate,
{
accepts: [
{arg: 'appId', type: 'string', required: true},
{arg: 'key', type: 'string', required: true}
],
returns: {arg: 'accessToken', type: 'object', root: true},
http: {verb: 'post'}
}
The text was updated successfully, but these errors were encountered: