Now that we have our fake repo and our “create” endpoint, it’s time to post some data. We also send back the json representation of entity we created, as it contains an id that the client will likely need for their next step. This will allow the client to understand not only that something went wrong, but we have the ability to communicate specifically what went wrong.įinally, if all has gone well, we send back the status code of 201, which means that the entity was successfully created. If that fails, we will do the right thing and not only respond with the appropriate status code, 422, but we will also send back the error in a json string. Imagine if someone wanted to send you 500GBs of json!Īfter we have read the body, we then Unmarshal it to our Todo struct. This is a good way to protect against malicious attacks on your server. The first thing we do is open up the body of the request.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |