rest2api

Light-weight server for REST APIs

Лицензия

Лицензия

Группа

Группа

eu.piotro
Идентификатор

Идентификатор

rest2api
Последняя версия

Последняя версия

1.3.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

rest2api
Light-weight server for REST APIs
Ссылка на сайт

Ссылка на сайт

https://github.com/piotro888/rest2api
Система контроля версий

Система контроля версий

https://github.com/piotro888/rest2api

Скачать rest2api

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/eu.piotro/rest2api/ -->
<dependency>
    <groupId>eu.piotro</groupId>
    <artifactId>rest2api</artifactId>
    <version>1.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/eu.piotro/rest2api/
implementation 'eu.piotro:rest2api:1.3.0'
// https://jarcasting.com/artifacts/eu.piotro/rest2api/
implementation ("eu.piotro:rest2api:1.3.0")
'eu.piotro:rest2api:jar:1.3.0'
<dependency org="eu.piotro" name="rest2api" rev="1.3.0">
  <artifact name="rest2api" type="jar" />
</dependency>
@Grapes(
@Grab(group='eu.piotro', module='rest2api', version='1.3.0')
)
libraryDependencies += "eu.piotro" % "rest2api" % "1.3.0"
[eu.piotro/rest2api "1.3.0"]

Зависимости

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.13.2

Модули Проекта

Данный проект не имеет модулей.

Rest2API

Maven Central Java CI Gradle

Lightweight Java server for REST APIs

Features

  • Easy to use with @RestHandler annotation
  • Lightweight, with no external dependencies
  • Universal - your handler methods assigned to URIs receive HttpRequest and return HttpResponse
  • Simple and fast, provides basic HTTP functionalities to run a REST (or other API over HTTP) application
  • Endpoint URIs supports regex and all HTTP methods.
  • Supports both static and non-static handler methods
  • Logs to java.util.logging.Logger
  • Queues connections and executes them via workers with customizable parameters

Usage example

import eu.piotro.rest2api.tcp.*;
import eu.piotro.rest2api.http.*;
import eu.piotro.rest2api.api.*;
import eu.piotro.rest2api.api.annotations.*;
import java.io.IOException;

public class REST {
    public void run() throws IOException {
        APIForwarder forwarder = new APIForwarder();
        forwarder.registerClassStatic(REST.class); // Process annotations for REST class and register handlers automatically
        //or forwarder.registerClass(new REST()); with non-static methods
        int PORT = 1234;
        Server server = new Server(PORT, forwarder);
        while(true){
            server.accept(); // Wait for incoming socket and execute it asynchronously
        }
    }
    
    @RESTHandler(method = "GET", URI = "/") // Annotation for APIForwarder to register method
    public static HTTPResponse getRoot(HTTPRequest request) { // Handler methods are assigned to URIs and HTTP Methods
        return new HTTPResponse(200, HTTPCodes.C200, "text/plain", "Hello World!"); 
    }
}

See javadoc for more details.

Installation

Gradle

dependencies {
    implementation 'eu.piotro:rest2api:CURRENT_VERSION'
}

Maven

<dependecies>
    <dependency>
        <groupId>eu.piotro</groupId>
        <artifactId>rest2api</artifactId>
        <version>CURRENT_VERSION</version>   
    </dependency>
</dependecies>

Replace CURRENT_VERSION with the latest version ex. 1.3.0

More customization

If built-in customization isn't enough, you can override APIForwarder class for custom routing or pass accepted Socket directly (or via ServerExecutor) to ConnectionHandler

Contributing

Feel free to open a new issue or change something via pull request!

Build via ./gradlew build

TODO

  • Support for persistent (keep-alive) connections
  • SSL/TLS (for now you can use proxy)

License

Licensed under MIT License

rest2api by Piotr Wegrzyn


Thanks for using/contributing

Версии библиотеки

Версия
1.3.0