Skip to content

CraftsBlock/CraftsNet

Repository files navigation

CraftsNet

Easy creation of HTTP routes and WebSocket endpoints in Java.

Latest Release on Maven GitHub code size in bytes GitHub GitHub all releases GitHub issues


CraftsNet is an easy-to-use Java library that enables developers to effortlessly create and manage HTTP routes and WebSocket endpoints in their server applications. This library greatly simplifies server development, allowing developers to focus on the actual functionality of their application without having to deal with complex server details.

Functions

  • Define and manage HTTP routes for different endpoints of the application.
  • Support for dynamic parameters in HTTP routes for more flexible functionality.
  • Effortless creation of WebSocket endpoints for real-time communication between server and client.
  • SSL support for secure and encrypted communication with users.
  • Addon based for easy expansion and maintenance

Installation

Maven

<repositories>
  ...
  <repository>
    <id>craftsblock-releases</id>
    <name>CraftsBlock Repositories</name>
    <url>https://repo.craftsblock.de/releases</url>
  </repository>
</repositories>
<dependencies>
  ...
  <dependency>
    <groupId>de.craftsblock</groupId>
    <artifactId>craftsnet</artifactId>
    <version>VERSION</version>
  </dependency>
</dependencies>

Gradle

repositories {
  ...
  maven { url "https://repo.craftsblock.de/releases" }
  mavenCentral()
}
dependencies {
  ...
  implementation "de.craftsblock:craftsnet:VERSION"
}

Quick Start

  1. Create an addon.json in your project in which you specify where your main class is located and what your addon is called.
{"name": "My Addon","main": "de.craftsblock.myaddon.MyAddon"}
  1. HTTP endpoints can be created as shown in the following example.
package de.craftsblock.myaddon;

import de.craftsblock.backend.api.http.Exchange;
import de.craftsblock.backend.api.http.RequestHandler;
import de.craftsblock.backend.api.http.Route;

public class MyRoute implements RequestHandler {
    
  @Route("/v1/route")
  public void handleRoute(Exchange exchange) {
    // Process the request
  }
    
}
  1. The following source code shows you how to create a WebSocket endpoint.
package de.craftsblock.myaddon;

import de.craftsblock.backend.api.websocket.MessageReceiver;
import de.craftsblock.backend.api.websocket.Socket;
import de.craftsblock.backend.api.websocket.SocketExchange;
import de.craftsblock.backend.api.websocket.SocketHandler;

public class MySocket implements SocketHandler {
    
  @Socket("/v1/socket")
  public void handleSocketMessage(SocketExchange exchange, String data) {
    // Process the socket message
  }
    
}
  1. Last but not least, you need the heart of your application, the Addon class. This is where all routes and endpoints are registered.
package de.craftsblock.myaddon;

import de.craftsblock.craftsnet.addon.Addon;

public class MyAddon extends Addon {

  @Override
  public void onEnable() {
    routeRegistry().register(new MyRoute());
    routeRegistry().register(new MySocket());
  }

  @Override
  public void onDisable() { }

}

Please visit our Wiki for a more detailed description.

Enable SSL

To enable SSL and enable a secure connection, you can simply add your SSL certificates. Currently only certificates issued by LetsEncrypt are accepted. You need the fullchain.pem and the privkey.pem which you have to put in the folder certificates so that CraftsNet recognizes them.

You can then enable SSL by appending --ssl to your startup command.

Open Source Licenses

We are using some third party open source libraries. Below you find a list of all third party open source libraries used:

Name Description Licecnse
CraftsCore https://repo.craftsblock.de/#/releases/de/craftsblock/craftscore Apache License 2.0
GSON A Java serialization/deserialization library to convert Java Objects into JSON and back Apache License 2.0
Apache Tika The Apache Tika toolkit detects and extracts metadata and text from over a thousand different file types (such as PPT, XLS, and PDF). Apache License 2.0
JetBrains Annotations Annotations for JVM-based languages. Apache License 2.0
Apache Maven Apache Maven core Apache License 2.0
Apache Maven-Resolver Apache Maven Artifact Resolver Apache License 2.0

Support and contribution

If you have any questions or have found a bug, please feel free to let us know in our issue tracker. We appreciate any help and welcome your contributions to improve the CraftsNet project.


Thank you for your interest in CraftsNet! We hope that you will benefit from this user-friendly Java library and use it to create powerful server applications. If you have any questions or suggestions, please feel free to contact us here!

About

Easy creation of HTTP routes and WebSocket endpoints in Java.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages