It appears that there is an issue passing the playerId parameter from the frontend to the backend in a React app. The createGame function in the Spring controller is set up to receive a playerId parameter, but the value is not being properly passed from the frontend using Axios. It has been attempted to use a Long and a String for the playerId, but the issue persists.
Still getting status 400 !
- Store it as a String parameter.
- I used @PathVariable.
- I tried to direct write the parameter in Postman.
- I tried change endpoint.
- Another endpoint (/login) which i’m not showing works good so no problem with proxy.
2
Answers
Daniel's answer is correct but I overwrite the code like this:
And the React will be send like this:
In shared React screenshot – it looks like you send a JSON body.
However, in Spring Controller – @RequestParam is used.
It looks like you either need to change React part to call URL like ‘/api/games/{playerId}’ (so playerId would be passed as part of URL) or update Spring Controller to accept @RequestBody (and create a class with field ‘playerId’) – so whole object could be passed as request body.
As currently React sends a body – but Spring is looking for a URL query param. Both parts need to do same thing – whatever it will be.
Spring changes would look like: