Closed frankcollins3 closed 1 year ago
first approach changed data to body
data: {
pokename: "squirtle",
pokeid: "6",
type: "water"
},
[7:28am]
updated this code to include JSON.stringify():
internal 500 server error: [7:34am]
tbh I still don't fully understand but some of that is becoming used to the ASP syntax:
// POST: api/pokemon
[HttpPost]
public async Task<ActionResult<Pokemon>> AddPokemon([FromBody] Pokemon pokemon)
{
try
{
// Add the new Pokemon to the context
_context.Pokemons.Add(pokemon);
await _context.SaveChangesAsync();
return CreatedAtAction(nameof(GetPokemon), new { id = pokemon.Id }, pokemon);
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while adding a Pokemon.");
return StatusCode(500, "A wild 500 error appears!");
}
}
[8:02am]
attempting to do: first ASP.net POST route
error:
proposed approach: check the POST body ?
possible improvements: