A HTTP Server tool developed as a learning exercise.
Made in Java. In London.
To get the application ready:
git clone ...
mvn package
To execute the server:
java -jar http-server-1.0.jar
To run the tests:
mvn test
To run the acceptance tests:
cd acceptance/
bundler install
bundler exec spinach
Here is the bootstrap code to start the server:
import core.Server;
public class Main {
public static void main(String... args) {
Server server = Server.defaultServer(5000); // port number: 5000.
server.start();
}
}
Take into account that unless created, the router won't have any default endpoints created,
returning therefor always NOT FOUND
.
In order to create a new endpoint simply extend from the base class Endpoint
and
implement all the HTTP methods you require, such as below:
package application;
import core.Endpoint;
import core.models.Request;
import core.models.Response;
public class HelloWorld extends Endpoint {
public String getUri() {
return "/hello-world";
}
@Override
public Response get(Request request) {
return Response.ok();
}
}
And then add the endpoint to the router:
Router router = server.getRouter();
router.add(new HelloWorld());