Passing data via POST body
While passing parameters via the URL is simple, there are a few problems with the URL approach. URLs can be cached by the browser and the user might end up selecting an autocompleted URL with data in the URL. This is good if we are using the URL to pass parameters to get data like visiting your profile on a social media application, however, we do not want to accidentally select a cached URL that alters data in the application.
Passing data in the URL is also limited to simple data types. For instance, if we wanted to pass a list of HashMap
s to the server, it would be hard to pass such a data struct through the URL without doing some other form of serialization. This is where POST requests and JSON bodies come in. We can pass JSON data via the HTTP request body.
We have already built our create function, but we need to refactor this create function so that we can integrate the create function into our web server. Our create function refactor results in the code...