Giter VIP home page Giter VIP logo

spear's Introduction

Spear

Spear is an annotation-based wrapper around Javalin that allows you to create and manage a number of routes effortlessly.

Spear also provides an optional end-to-end typesafe API client and server.

Spear is inspired by the Spring framework, and aims to provide an easy way to create and manage routes in a Javalin application.

Example "route-only" Usage:

public class TestMain {
    public static void main(String[] args) {
        Spear.bind(Javalin.create())
                .register(new TestController())
                .start(8080);
    }
}

@Route("/test")
public class TestController implements SpearHandler {
    @Route(value = "/", method = HttpMethod.GET) // hit localhost:8080/test/
    public void test(Context ctx) {
        System.out.println("Hello, World!");
        ctx.result("HW1");
    }
    @Route(value = "/{pathparam}", method = HttpMethod.GET) // hit localhost:8080/test/paramnamehere
    public String test2(Context ctx, @PathParam("pathparam") String param) {
        return param;
    }
}

Example Client & Server:

public class ServerMain {
    public static void main(String[] args) {
        Spear.bind(Javalin.create())
                .register(new TestHandler())
                .start(8080);
    }
}


public record TestResponse(String response) {}

@Route("/test")
public record TestRequest(String str) implements APIRequest<TestResponse> {}

public class TestHandler implements APIHandler<TestResponse, TestRequest> {
    @Override
    public TestResponse handle(TestAPIRequest request, Context ctx) {
        System.out.println("Received request: " + request.str());
        return new TestResponse("Hello world!");
    }
}

public class ClientMain {
    public static void main(String[] args) {
        new SpearCommons(new Gson(), "http://localhost:8089", builder -> builder);
        new TestRequest("Hi").send().thenAccept(System.out::println);
    }
}

See the example module for more examples.

Sponsors

This project is proudly brought to you by jank

spear's People

Contributors

badbird5907 avatar

Stargazers

dev.malvarado avatar  avatar RunTheBot 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.