Giter VIP home page Giter VIP logo

webserver's Introduction

webserver

Guice WebServer Module - backed by latest Jetty, Jersey and Jackson. Without HK2-Guice bridge.

Library is useful for lite web services. Following JAX-RS convention it's so easy to write from simple to very complex REST endpoints. Library is simple, fast with small footprint. The library is written to fully support JSON as input and output format.

Build Status

Dependencies

  • Guice
  • Jetty
  • Jersey
  • Jackson 2 (Transitive)

Installation

In your POM file, add following dependency:

<dependency>
  <groupId>com.sorskod.webserver</groupId>
  <artifactId>webserver</artifactId>
  <version>1.1.0</version>
</dependency>

Note: You may want to check for the latest version.

Snapshot installation

For the latest snapshot version, you need to add add OSS Sonartype repository to your POM file and the following dependency:

<project>
    <repositories>
        <repository>
            <id>oss-sonatype</id>
            <name>oss-sonatype</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
          <groupId>com.sorskod.webserver</groupId>
          <artifactId>webserver</artifactId>
          <version>1.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

Usage

There is a working example in test package. However, here is the short guideline:

  1. Bind all JAX-RS resource classes in Guice context. (All classes annotated with @Path will be registered in Jersey's context. Jersey's auto-discovery feature is disabled.)
  2. Install WebServerModule
  3. Install HTTPConnectorModule or/and HTTPSConnectorModule
  4. Provide Configurator implementation
  5. Inject Jetty Server and call start()

Example:

public class MyModule extends AbstractModule {
  
  protected void configure() {
    
    // Bind @Path annotated classes
    bind(MyHttpResource.class);
  }
  
  @Provides
  @DefaultConnector
  Configurator configuratorProvider() {
    return () -> 8080; // WebServer port 
  }
  
  @ProvidesIntoSet
  Feature customJaxrsFeature() {
    // Provide custom features, register filters, etc 
    return (context) -> {};
  }
}

Injector injector = Guice.createInjector(new WebServerModule(), 
                                         new HTTPConnectorModule(),
                                         new MyModule());


injector.getInstance(Server.class).start();

NOTE

Library is written for fun and test purposes. Pull requests and improvement ideas are welcome.

TODO

  • Remove HK2 and make Guice as only DI framework (Hard to accomplish)
  • README & Wiki
  • Example project

webserver's People

Contributors

dependabot[bot] avatar salebab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

webserver's Issues

[Q] Which dependencies do I need to declare?

Which dependencies do I need to declare in my project beside your module?

If I add

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
    <scope>compile</scope>
</dependency>

the server does not start-up.

When it does start-up I get:

...
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.util.BeanUtil.okNameForSetter(Lcom/fasterxml/jackson/databind/introspect/AnnotatedMethod;Z)Ljava/lang/String;

Thanks for helping me out :)

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.