@RequestBody("title") title : string
should be returns null / undefined values when property title is null or undefined in body
When I post as body a json data like that
{
"customerId" : 234,
"title" : null,
"firstname" : "Alex"
}
and I'm using a property attribute like that
@RequestBody("title") title : string
title variable contains all body data instead of null.
I think in server.js the function getParam in that line
return param[name] || this.checkQueryParam(paramType, param);
should be
if (paramType === "query") {
return param[name] || undefined;
} else if (paramType === "body") {
return param[name];
}
return param[name] || param;
or something better.
{
"customerId" : 234,
"title" : null,
"firstname" : "Alex"
}
inside the controller use a property attribute like that
@RequestBody("title") title : string
title variable contains all body data instead of null.
I'm simply posting data to a controller :)
@requestBody() does not take any arguments. It was intended to supply the body of the request as an object so that you can apply a type to it. So in your case:
interface Customer {
customerId: number;
title: string;
firstName: string;
}
and the method
@post('/')
public addCustomer (@responseBody() customer: Customer): any {
let title = customer.title;
}
@AltekkeE can we throw or something is someone tries to use it with args @RequestBody("xxx")? Should that not be a compilation error.
I don't see why not
@massivedynamicsrls are you using TypeScript? how did you pass arguments to RequestBody without getting a compilation error?
I can confirm that typescript compilation goes without any errors.
Also, when you have @RequestBody("title") title : string it'll extract "title" parameter from the body, it "title" parameter is part of the body, but if parameter "title" doesn't exist, it'll pick up entire body.
I would say that behaviour isn't consistent. If it's designed to extract entire body, that shouldn't extract any parameter in any case.
#161 thanks!
5.2.2
The docs still state that RequestBody annotation does get an argument. Probably should be fixed.
Most helpful comment
@requestBody()does not take any arguments. It was intended to supply the body of the request as an object so that you can apply a type to it. So in your case:and the method