Navigation Menu

Skip to content

Manzanit0/HttpServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Server

Build Status codecov

A HTTP Server tool developed as a learning exercise.

Made in Java. In London.

Getting started

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

Starting up the server

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.

Creating a new endpoint

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());

About

HTTP server implementation in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published