Giter Site home page Giter Site logo

michailivanov / httpserver Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 204 KB

This is a simple HTTP server implemented in Java using non-blocking I/O with the `java.nio` package. The server supports handling GET, POST, PUT, PATCH, and DELETE requests.

Java 100.00%

httpserver's Introduction

Simple HTTP Server

This is a simple HTTP server implemented in Java using non-blocking I/O with the java.nio package. The server supports handling GET, POST, PUT, PATCH, and DELETE requests.

Features

  • Handles GET, POST, PUT, PATCH, and DELETE requests
  • Supports JSON and multipart/form-data request bodies
  • Allows registering custom handlers for specific paths and HTTP methods

Getting Started

To run the HTTP server, follow these steps:

  1. Clone the repository: git clone https://github.com/your-username/http-server.git

  2. Navigate to the project directory: cd httpServer

  3. Compile the Java source files: mvn clean package

  4. Run the server: java -jar target/httpServer-1.0-SNAPSHOT.jar

The server will start running on localhost with the port 8081.

Usage

You can use Postman to send requests to the server. Here some examples:

GET Request

Send a GET request to the server:

GET Request

POST Request with JSON Body

Send a POST request with a JSON body:

POST Request with JSON

PUT Request with Multipart/Form-Data

Send a PUT request with multipart/form-data containing form fields and files:

PUT Request with Multipart/Form-Data

PATCH Request

Send a PATCH request with a request body:

PATCH Request

DELETE Request

Send a DELETE request:

DELETE Request

Customization

To add handlers for specific paths and HTTP methods you can create a new instance of the Handler interface and register it using the registerHandler method of the Server class.

For example:

Server server = new Server("localhost", 8081);
server.registerHandler("/hello", "GET", (req, res) -> {
    res.sendText(200, "Hello, World!");
});

httpserver's People

Contributors

michailivanov avatar

Watchers

 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.