mean-expert-official / loopback-sdk-builder

Tool for auto-generating Software Development Kits (SDKs) for LoopBack
Other
399 stars 178 forks source link

Custom remoteMethod with POST is generated as GET #531

Open vegham opened 6 years ago

vegham commented 6 years ago

What type of issue are you creating?

What version of this module are you using?

Issue: Data which should be posted in body is appended to URL. I discovered this when server gave me 414 URI Too Long.

Details: The generated a custom function in service/custom/Mymodel.ts has correctly _method = POST, but data which should be in _postBody is in _urlParams.

jmls commented 6 years ago

yeah, I've seen that a lot recently as well. very confusing - and not nice on the eye for the generated url ;)

jonathan-casarrubias commented 6 years ago

Hi guys thanks for reaching out..

Hey so, the sdk right now is not deciding the type of data based on your remote method HTTP method, but it addresses your arguments configurations.

In other words the SDK is only addressing the HTTP Mapping from arguments configurations

{ arg: 'data', type: 'object', http: { source: 'body' } }

Reference: https://loopback.io/doc/en/lb2/Remote-methods.html#http-mapping-of-input-arguments

If you don't map your arguments the SDK by default will send everything through query params which is default.

Once you correctly configure your arguments, your generated remote method will work as you expect.

Of course it can be improved and also address HTTP Methods to decide the type of the parameter in case the HTTP Mapping is not provided. PRs Are Welcome :)

Regards Jon

blue-cp commented 6 years ago

+1

I am using version number: 2.1.1 @jonathan-casarrubias having same exact issue on our side. I manually changed the code in the generated sdk on my end. to from _postbody instead of _urlParams.

Any updates on this issue?