Git Product home page Git Product logo

alakazam's Introduction

Alakazam! Build Status

Web application server based on Jetty, RestEasy, and Jackson.

Background

This project began as a fork of the DropWizard codebase.

http://www.dropwizard.io/

DropWizard is a great project, however some of the open source licenses used as part of DW were an issue for a commercial project I was working on. Alakazam is the result of replacing some of those parts with more lenient equivalents.

Much deserved credit to Coda Hale and the DropWizard team. If your requirements allow, consider using DropWizard over Alakazam, where possible.

Basic Usage

Main Class

import io.alakazam.Application;
import io.alakazam.assets.ConfiguredAssetsBundle;
import io.alakazam.setup.Bootstrap;
import io.alakazam.setup.Environment;

public class MyMainClass extends Application<MyConfigClass> {

    public static void main(String[] args) throws Exception {
        new MyMainClass().run(args);
    }

    @Override
    public String getName() {
        return "my-web-server";
    }

    @Override
    public void initialize(Bootstrap<MyConfigClass> bootstrap) {
        //optionally register a Java resource directory to serve static files from
        bootstrap.addBundle(new ConfiguredAssetsBundle("/images/", "/images/"));
    }

    @Override
    public void run(MyConfigClass configuration, Environment environment) throws Exception {
        environment.resteasy().register(new MyRESTResource(), false);
    }

}

Config Class

import io.alakazam.Configuration;
import io.alakazam.assets.AssetsBundleConfiguration;

public class MyConfigClass extends Configuration implements AssetsBundleConfiguration {

    @JsonProperty("myConfig")
    private String myConfig;

    public String getMyConfig() {
        return myConfig;
    }
}

Config File (server-config.yml)

myConfig: "myConfigValue"

REST Resource

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/myresource")
@Produces(MediaType.APPLICATION_JSON)
public class MyRESTResource {

    @GET
    public Response handleRequest() {
        String json = "{\"foo\":\"bar\"}";
        return Response
                .ok(json)
                .header("Content-Length", json.length())
                .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON + "; charset=ISO-8859-15")
                .build();
    }

}

Start the Server

java -cp <your-classpath> my.package.MyMainClass server server-config.yml

alakazam's People

Contributors

jasongardnerlv avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

animeshinvinci

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.