Giter Site home page Giter Site logo

http-server's Introduction

HTTP Server

This is a simple server built with Java 10. It can receive, parse, handle, and respond to HTTP 1.1 requests. For more detailed functionality and limitations, see Supported Functionality.

Dependencies

Starting the Server

On Default Port and Directory

  1. Navigate to the root directory
  2. Run the following gradle tasks
    gradle assemble
    gradle startDemoServer
    
  • The default port is 8888
  • The default directory from which to serve files is the following directory: src/test/resources/demoFiles

On Custom Port and Custom Data Store

  1. Navigate to the root directory.

  2. Create a JAR file using Gradle. This will create the build directory.

    gradle jar
    
  3. Navigate to the directory where the jar file is located.

    cd build/libs
    
  4. Run the JAR file with a port flag (-port) and number as well as a directory flag (-dir) and a directory path.

    java -jar http-server.jar -port 4444 -dir src/test/resources/demoFiles 
    
  5. Fire away at the server! Using your browser, cURL, Postman, etc., navigate to http://localhost:PORT_NUMBER

Running Tests

Unit tests covering this project are written with the JUnit testing framework. Acceptance tests are written using Cucumber. To run acceptance tests, the server must be running on port 8888 and serving content from src/test/resources/testFiles:

  1. Navigate to the root directory.
  2. Run the following gradle tasks:
    gradle assemble
    gradle startTestServer
    
  3. Run gradle test.
  4. To automatically rerun tests after changing the code, run gradle -t test to simultaneously build the output and run all unit tests.

Supported Functionality

Endpoints

URL Supported Methods Supported Media
/* OPTIONS N/A
/api/form OPTIONS, POST application/x-www-url-form-encoded
/api/people OPTIONS, POST application/JSON, text/plain
/api/query GET, OPTIONS N/A
/echo GET, OPTIONS N/A

Static Files

To determine which HTTP methods can be applied to a static resource, you can make an OPTIONS request to that resource.

OPTIONS

All static files and endpoints can handle OPTIONS requests.

GET

All static files can handle GET requests.

HEAD

All static files can handle HEAD requests.

PUT

A PUT request to an existing static resource will overwrite the resource using the request entity. A PUT request to a nonexistent resource will create that resource using the request entity.

PATCH

Currently, only JSON resources can be PATCHed, and the patch document must be of type application/json-patch+json.

The server's handling of JSON Patch is limited. Arrays cannot be added as values or modified. Additionally, nested JSON objects cannot be added as values, but individual key/value pairs in an existing, nested JSON object can be manipulated using any of the JSON Patch operations.

DELETE

All static files can handle DELETE requests.

Middleware

The server makes use of a chain of middleware classes to operate on requests and responses. All Middleware classes extend the Middleware class. The middleware chain can be configured in the #getMiddlewareChain method of the MiddlewareConfig class.

The middleware chain currently consists of the following classes:

  1. CorsMiddleware
  2. Logger
  3. Authenticator

Protected Routes

Routes can optionally be protected with HTTP authentication. Credentials for a protected route are set in #setUpAuthenticator in the MiddlewareConfig class. Routes that should be protected can also be added within this same method.

Contributing

  1. Fork the repository.
  2. Create a feature branch using Git.
  3. Write your feature in the src/main/java directory.
  4. Write a unit test (covering every new public method) in the src/test/java directory.
  5. Run gradle build to ensure that the application successfully builds and passes all tests.
  6. Create a pull request.

http-server's People

Contributors

omarnyte avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.