I have a Spring Boot REST endpoint written in Kotlin as such:
@GetMapping(value="/transferDetails")
private fun transferAccountDetails(@RequestBody transferAcctDetails: TransferAccountDetails):results{
/** Hidden logic*/
return results(true,"Details Transferred Successfully")
}
//region Data View classes for HTTP response are defined here
data class TransferAccountDetails(val ownerKey: String, val counterPartyKey: String, val acctId: String)
What the above endpoint does is merely taking the parameters from the request body and make some changes to the database and eventually return a success message.
Let say I cannot change the behavior or the request type used for this endpoint (e.g. POST
or PathVariable
) and that the above script is final and has been tested with Postman and it works.
On the frontend, I am using Angular and sending the request to the above endpoint in my service
as follows:
processAccountDetailsUrl = 'http://.../api/transferDetails';
processAccountDetails(ownerKey: string, counterPartyKey: string, acctId: string) {
this.paramsDict = {
ownerKey: { ownerKey},
counterPartyKey: { counterPartyKey},
acctId: { acctId }
};
this.requestOptions = {
params: new HttpParams(this.paramsDict)
};
return this.http.get(this.processAccountDetailsUrl , this.requestOptions);
}
I am getting the following error 400:
{
"timestamp": "2019-11-29T08:16:52.793+0000",
"status": 400,
"error": "Bad Request",
"message": "Required request body is missing: private final com.template.webserver.results..."
"path": "/api/transferAccountDetails"
}
Is requestOptions
not the way to add request body to a GET
request? If so, what changes should I make to be able to call the REST endpoint and where did it go wrong? Assume that I can only edit the frontend and the backend has been tested to be working and no further changes should be made.
I tried creating an interface in my TS file that has the same variables as the data class TransferAccountDetails
and tried parsing it like return this.http.get(this.processAccountDetailsUrl , this.theInterfaceObject);
. This is not working as it is not a type for a GET
request.