-
Notifications
You must be signed in to change notification settings - Fork 81
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
Support http.source configuration in datasources.json templates. #20
Comments
The primary purpose of the operation template is to define the structure of the REST request and extract variables as parameters for the proxy method in Node. How to map the proxy method into a new REST api is a separate concern. There are a few potential ways to derive the
Patches are welcome. |
Raymond, Thanks for your response. I want to preface, that I am just getting started playing around with Loopback so it is VERY possible that I have no idea what I am doing :P. Say I have defined a datasource as follows:
The apparent behavior is
In order to execute the previous HTTP request, an API is automatically created that defines:
In my ideal situation, I would like to hit my loopback server as follows.
Based on your response (option 2), I tried modifying my 'myModel.js' as follows:
I do not see the corresponding 'doSomething' endpoint changes represented in the explorer (they still show as 'query' source params. Note: I have been able to work around this on my own by excluding the 'function' argument from datasources.json and manually attaching a function to my 'myModel' like:
But this seems like a lot of boilerplate to achieve (what seems to me) as a common usecase. Apologies in advance if this is just a newbie error. |
It's a timing issue. The remoteMethod is called too early inside the model extension js file. You can either move the code to be an event listener of |
Thanks Ray, I was unable to get it to work using,
but the following did work:
I'm unblocked for now. Would still like to see either better documentation around the default api's that are created from the templates (and maybe some guidelines on doing what I'm trying to do) or the functionality originally requested in this issue. Thanks for the help! |
How do I set dynamic / custom headers in the data source file ? I've observed, they work only if if put them in the data source file. |
@aroramayur, please ask your question in one of the following locations:
Hopefully you will actually get an answer when you post in there 😃. @ctotheameron, I assume that you have figured this out from your last comment. I will now close the issue but please feel free to re-open if need be (just make sure your mention me in a comment so I can tend to it right away). |
Currently when reading the operations[template] from datasources.json, rest-connector.js hardcodes the source value to "query". I have many use-cases where I would like to configure the source value of my params without having to write custom code.
See:
https://github.com/strongloop/loopback-connector-rest/blob/master/lib/rest-connector.js#L56
My proposal would be to extend the variable definition syntax to include param source. Something like:
'{x=100:number#path}'
Happy to take a crack at this and submit a PR if you think it's worth implementing.
The text was updated successfully, but these errors were encountered: