#{extends '../main.html'/}# #{set title:'Webpieces Design'/}# #{set tab:'management'/}#
Many webservers allow developers to make the mistake where the following windows will pop up to users.
This prompt is confusing as hell to users and you should never show this dialogue....ever! This is the fault of
Webpieces forces you into the PRG pattern such that you cannot send a response to a post that is not a redirect unless
For all html pages, POST requests always result in a redirect saving you many many headaches.
More information can be found on the Wikipedia PRG page
Next, on a POST request with all the user data like user name, email, phone number, address, password, since we are sending a redirect back, we could possibly lose what the user typed in. This would be really annoying to the user and is where the 'Flash Scope' comes into play. The Flash Scope is a special cookie where the user info is saved on the post and destroyed after the GET request. Post, Redirect, Get happens so fast, this scope only lasts milliseconds over a good network connection.
With this new information, we can now look closer at the MVC pattern with respect to
As a side note, http does have PUT and DELETE so essentially, the CRUD operations(Create, Read, Update, Delete) in theory are POST, GET, PUT, DELETE in http. However, due to legacy reasons, browsers only use POST for forms not PUT so even on updates/deletes, a POST will be performed instead of a PUT or DELETE. This is just the way browsers work. In theory, some developers may see this as unclean but in practice, it really doesn't hurt that much in terms of creating a webserver. If you are developing an JSON api, you 'could' use all 4, but again in practice, clients and customers really don't give a crap, but we leave the apis up to you. We have found what is far more important is the documentation behind the api rather than these types of detailed decisions.
Webpieces is designed such that EVERYTHING is a library including the main webserver. Here is a full picture of the dependencies between the most important jar files.
Notice that http-webserver really only depends on 3 things to create the webserver
Notice that any one of these pieces could be taken to build another webserver. http-router actually knows nothing about http and only knows of a RouterRequest keeping it independet of protocol. http-webserver is the glue between these 3 main pieces of the webserver.
Of course, digging deeper, http2-frontend2 depends on even more pieces and in fact some of those pieces are what are used to build the http-client that is independent of the http-webserver.
Requests in bytes come into the 'core-channelmanager' at which point 'http-frontend' is listening and receives those bytes and has the http1 or http2 parser parse the bytes. http-frontend does http1/http2 detection when the socket connects for the first time. Once http-frontend has parsed the bytes into an http object, it fires it to the a listener. The listener was added by the http-webserver. At this point, the http-webserver translates the http request into a router request for the router and calls the router. The router then finds the route and calls the controller which sends back redirect or render response. In the case of render response, the webesrver then calls into http-templating to render a response and sends that back to the client. If the controller sends back a redirect, the http-templating is skipped.
A Webpieces application follows the MVC(Model-View-Controller) architectural pattern applied to the web architecture.
This pattern splits the application into separate layers:
I want to be clear about this next picture. http-frontend does NOT depend on webserver but rather the webserver adds a listener to http-frontend so it can receive all new http requests, but this diagram is 'not' a dependency diagram but an object flow diagram so you can see how requests flow through the pieces of webpieces and to your controller
Again, the 3 situations a POST will occur are create/update/delete. From the user perspective, for create or update, he is just filling in a form and clicking save or submit.
In this diagram, the V in MVC is never used. All that happens is the controller validates the values in the form and saves the model to the database and then redirects the browser to a new page perhaps to display the newly created record. We show the GET request in the next section for reading that newly created record.
The flow for a GET http request looks like so