Giter VIP home page Giter VIP logo

ratpack's Introduction

Build Status codecov.io Revved up by Develocity

Ratpack.io

What is Ratpack?

Ratpack is a simple, capable, toolkit for creating high performance web applications.

Ratpack is built on Java and the Netty event-driven networking engine. The API is optimized for Groovy and Java 8.

Optional Google Guice integration provides a foundation for scaling your application in size in a managed way.

Optional Gradle build time support makes building and testing applications a breeze.

http://www.ratpack.io

Looking to contribute?

Please see CONTRIBUTING.md

ratpack's People

Contributors

beckje01 avatar bnavetta avatar brucenunk avatar danhyun avatar danthegoodman avatar danveloper avatar davidmc24 avatar davydotcom avatar drmaas avatar erdi avatar felipefzdz avatar fromanator avatar gsaqui avatar jeff-blaisdell avatar johnrengelman avatar jprinet avatar justinvoss avatar ldaley avatar leleuj avatar lhotari avatar melix avatar pledbrook avatar raymyers avatar rhart avatar robfletcher avatar runningcode avatar stefanogualdi avatar tlberglund avatar wololock avatar zedar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ratpack's Issues

Create preliminary user manual

(this issue is for creating the very first public version of the manua – it doesn't need to be comprehensive)

Ratpack needs a basic user manual covering:

  1. Introduction
  2. Quick start
  3. Basic mechanics
  4. Scripts vs apps
  5. Sync vs async
  6. Extensions (modules)

Pre load Groovy in the background when starting a Groovy app

At the moment, Groovy is not touched until the first request is handled. This makes Ratpack feel sluggish as it has to bootstrap Groovy at this time.

We could improve this by bootstrapping Groovy in the background as soon as the app starts.

redirect() should intelligently create the Location header

The HTTP spec requires that the Location header on redirects is an absolute URL. For application developers, that's a complete pain in the backside. So, Response.redirect() should do the following:

  1. if given an absolute URL, redirect() should put that URL straight into the Location header
  2. if given a URL starting with a slash, '/', redirect() should prepend the public-facing domain and port if provided, otherwise the base URL of the request.
  3. if given a relative URL (with no leading '/'), redirect() should prepend the public-facing domain and port if provided plus the parent path of the request URL, otherwise the full parent path (including domain and port).

Given a public-facing URL of http://www.ratpack-framework.org and a request to http://localhost:5050/posts/list :

"index" --> http://www.ratpack-framework.org/posts/index
"/index.html" --> http://www.ratpack-framework.org/index.html

If there is no public-facing URL configured:

"index" --> http://localhost:5050/posts/index
"/index.html" --> http://localhost:5050/index.html

Add exception handling

I tried a simple Ratpack app that threw an exception when handling a request. The browser then just stuck at "waiting for response". Missing exception handler? Here's the exception stacktrace:

May 02, 2013 8:53:24 AM org.ratpackframework.bootstrap.internal.NettyRatpackServer startUp
INFO: Ratpack started for http://0:0:0:0:0:0:0:0:5050
May 02, 2013 8:53:40 AM org.ratpackframework.handler.NettyRoutingAdapter messageReceived
INFO: received /
May 02, 2013 8:53:40 AM org.jboss.netty.channel.SimpleChannelUpstreamHandler
WARNING: EXCEPTION, please implement org.ratpackframework.handler.NettyRoutingAdapter.exceptionCaught() for proper handling.
java.lang.AssertionError: Bintray user name must be specified in $BINTRAY_USER.    Expression: bintrayUser. Values: bintrayUser = null

Define what is expected of a renderer

This issue on the ratpack-site project got me thinking about the roles and responsibilities of a 'standard' Ratpack renderer. My current thoughts:

  1. A renderer should be able to generate content based on source from any location, be that the filesystem, a database, or a JAR.
  2. A renderer should generate content to any output stream/writer
  3. A renderer should add appropriate content-type and encoding headers to a response, but the app developer must be able to override these.

I'm not sure whether a renderer should do anything with cache headers. I'd be interest in feedback from others.

Style Javadoc

The Javadoc will be the main reference documentation (linked to throughout the manual) so should look good.

I don't have any real ideas on what it should look like. Just a bit nicer than the default Java 7 skin.

Define pluggable template renderer strategy

At the moment, there is a concept of a global renderer.

See: https://github.com/ratpack/ratpack/blob/master/ratpack-core/src/main/java/org/ratpackframework/bootstrap/internal/RootModule.java#L86

Extension modules simply bind a different impl of https://github.com/ratpack/ratpack/blob/master/ratpack-core/src/main/java/org/ratpackframework/templating/TemplateRenderer.java to override the template renderer.

The benefit of doing this is integration with this method: https://github.com/ratpack/ratpack/blob/master/ratpack-core/src/main/java/org/ratpackframework/app/Response.java#L65

This is convenient for users in that they just call a render method in their handler. However, the cost is that the user can only provide the rendering engine two things for a rendering operation; a template id and a model map.

I propose that we drop template rendering as concern of the core. If you want to use a template solution, you define whatever types you like as the interface and simply inject them into your endpoints…

class MyEndpoint implements Endpoint {

  final MarkdownRenderer renderer

  @Inject
  MyEndpoint(MarkdownRenderer renderer) {
    this.renderer = renderer
  }

  void respond(Request request, Response response) {
      renderer.render("foo", response)
  }

}

The groovy module could still support the Response.render() method as an extension. This wouldn't prevent using other renderers with the Groovy module.

Make configuration extensible

Currently, the config API is statically defined and not extensible. It needs to be extensible.

At the moment, the only SPI is the ability to inject Guice modules. Guice doesn't define any lifecycle. It simply creates an "application context" which you can retrieve beans from. We will likely need to implement our own lifecycle and make it fundamental to the way Ratpack bootstraps.

This is my proposed plan:

There are two distinct phases of bootstrapping; config then application. This creates a separation between config extension modules and application extension modules. Config types have no access to runtime types, but app types can depend on config types (in order to configure themselves).

We introduce RatpackAppBuilder, which looks like this:

interface RatpackAppBuilder {

    // Mutable list of modules defining config time beans
    List<Module> getConfigModules()

    // Callback called by Ratpack after initializing all config modules
    // Allows access to mutate the config beans before the runtime is bootstrapped
    void onConfig(Handler<Config>)

    // Mutable list of modules defining runtime beans
    List<Module> getRuntimeModules()

}

Config.groovy looks something like this:

interface Config {
    <T> T get(T configObjectType)
    <T> T config(T configObjectType, Handler<T> configurer)
}

(you can infer the closure overrides for the Groovy module)

In the Groovy script mode, this type backs the config.groovy script…

configModules << new MyConfigExtensionModule()

onConfig {
    config(MyCustomConfigObject) {
        someSetting = foo
    }
}

runtimeModules << new MyRuntimeModuleThatDependsOnMyCustomConfigObject()

It does mean that there is no static list of config options, but there can't be if it is to be extensible.

Ensure the manual works in IE

In terms of support I intend…

  • IE9+ should be 100%. Currently there are only a couple of glitches.
  • IE8 doesn't support media queries or pseudo-elements so the layout, logo and chapter dividers are broken. Some simple CSS rules should be able to make them acceptable at least.
  • IE<=7 I'm inclined to just turn the stylesheet off using a conditional comment and load a different one with a few very very basic tweaks so that the content is readable.

Common styling for manual & site

Possibly we can use a git sub-module to house the SASS source which can be shared between the two projects.

I envisage having distinct top-level stylesheets each of which pulls in a bunch of common components.

Deploy Ratpack application on Heroku

In order to deploy on Heroku, a buildpack is required to release your application.

The official Gradle buildpack is stuck on Gradle 1.0-milestone-5 and jdk6. Besides that, it is very brittle and quite broken. I decided to set up a brand new buildpack that runs Gradle 1.5 with jdk1.7. You can find the preliminary version under heroku-buildpack-gradle-jdk7.

I've managed to get the groovy-console example app up on Heroku, although it runs out of memory on invocation of gradle run. Seems like the quota is 512M on Heroku, so will look into tweaking the heap size on command invocation.

Another problem that needs to be resolved: Heroku seeks to set the port dynamically on bootstrapping of the app. It expects the app to pick up environment variable PORT and dynamically configure itself to use it at runtime. Heroku then routes all requests to the application through the port that it provided earlier.

I was looking at #5 and noticed some mentions of AddressConfig. We would probably need to inject the result of PORT into the port field of this object on startup of the app as part of the application lifecycle. Since this still seems to be under discussion at the moment, I will wait until it's better defined.

Degenerify RoutingBuilder

It would be more user friendly if this wasn't a generic type.

Not quite sure how this is going to work yet, considering the Groovy subclass.

Place public (aka web-app or docroot) folder higher in the directory hierarchy

I'm sure it's possible to relocate public with configuration (though I don't know how.) But, I'd recommend placing it higher by default (e.g. putting it in the root of the project.) I like the way Grails does it, though you may not want to use the name web-app since that is a Servlets convention.

I think that front-end developers will like the framework better if the docroot is not so deeply nested. Remember not everyone wants to use an IDE.

Report MissingMethod/PropertyExceptions from Groovy DSL in a user-friendly way

Consider this script fragment:

ratpack {
    module {
        ...
    }

    routes {
        gets {
            response.send "Hello World!"
        }
    }
}

The module(), routes() and gets() methods are all invalid, but all the user sees is a massive stack trace. It would be better to report them as invalid parts of the DSL with a simple, clear message.

It might make sense to have a system property or two to manage stacktrace reporting.

Missing POST route does not cause an error

Following Tim's recent Ratpack presentation at 33rd Degree

https://github.com/tlberglund/33rd-degree-ratpack

At one point the application had a GET route defined as

get('/lookup') {
    render('artist.html')
}

The template artists.html had a form with POST as the method. Clicking on the button produced an empty page. There was no error on the console. I believe this case should cause and error as there is no exact route defined for POST('/lookup') and apparently GET('/lookup') did not handle the request either.

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.