Nhu Nguyen 46ffffd276 add link to read me | пре 6 година | |
---|---|---|
src | пре 6 година | |
.gitignore | пре 6 година | |
README.md | пре 6 година | |
pom.xml | пре 6 година |
The training wheels are coming off....sort of. In this lab, I set up the basic server for you. Your task is to handle other type of responses. You can refactor the code however you see fit and I highly advise you to do so.
Read the wiki page HTTP and figure out how to write the response for each of the request. I wrote a sample one for you to see. In src/main/java/Main.java
, run the main
method. Once the server is up, go http://localhost:5000
, note it says Hello world
.
Your task for this lab is to read the HTTP and figure out how to generate the proper response. Remember to write unit test.
I will not answer the following questions:
If you come to me, I will show you LMGTFY(Let me google that for you). I will answer anything related to why your code doesn't work. I will also answer design related questions. I will also help you construct the test if you know what message you want to write.
http://localhost:5000/hello
path which will return world
as a responsehttp://localhost:5000/form?key=value
path which will return the value as a response. For example if I call /form?search=blue
, the server will return blue
. If I call /form?color=red
, the server will return red
. The response code should be 201
.http://localhost:5000/404
path which will Are you lost?
with 404
response code./form?key=value
path so it will only response if it is a POST
request. Any other type of request will a 404
response.http://localhost:5000/redirect
path which will redirect you to http://google.com
Currently our server can handle one request at a time. This is called Synchronous. We want multiple users to access the server at the same time. This is called Asynchronous. Read up on the term here.
run
method of the RequestHandler
, add Thread.sleep(5000);
before the try and catch to make your server go to sleep for 5s before processing your request.
http://localhost:5000
http://localhost:5000
/files/[image_name]
(e.g. /files/high5.gif
) will show the imagehttp://localhost:5000/files
path. The files path will list out all the files in the src/main/resources
folder in a list.long id
and String name
http://localhost:5000/users
path to display all the users name in a list.http://localhost:5000/users/1
to show information for the first user (their name and id)http://localhost:5000/users/new
path to show a form where user can enter a name to create a new user.http://localhost:5000/users
with a POST
method to accept the form information and create the user. Redirect to /users/[user_id]