Skip to content

Instantly share code, notes, and snippets.

View danbev's full-sized avatar
⌨️
T.C.B "Taking care of business." Cosmo Kramer

Daniel Bevenius danbev

⌨️
T.C.B "Taking care of business." Cosmo Kramer
View GitHub Profile
@danbev
danbev / gist:4671767
Last active December 11, 2015 22:48
Grunt

Upgrading from Grunt 0.3.x to 0.4.x

It turns out that grunt 0.3.x and 0.4.x have changed quite a bit and for a newbie like me this can be confusing. Perhaps this might save others in the team from scratching their heads when trying to build aerogear-js.

Grunt 0.4.x has tree parts to it:

  1. grunt
    The npm module grunt should be installed locally to your project.

  2. grunt-cli
    The npm module grunt-cli should be installed globally. It puts the grunt command in your PATH so you can execute it anywhere.

@danbev
danbev / gist:4655294
Last active December 11, 2015 20:28
What's new in AeroGear Controller 1.0.0M8

What's new in AeroGear Controller M8

With the 1.0.0.M8 release of AeroGear-Controller we have added the following features:

  • Pagination support
  • Consuming/Producing custom media types

Pagination in AeroGear Controller

Pagination is the ability to return a limited number of elements in response to a call. The number of elements returned is referred to as a page. In AeroGear controller the strategy used for implementing pagination is using a offset/limit:

  • offset
    The offset of the first element that should be included in the returned collection. Default value is 0.
  • limit
@danbev
danbev / gist:4585554
Created January 21, 2013 11:54
Error Message in AeroGear Controller Demo

Missing Parameter in the Request

Route:

route()
      .from("/cars")
      .on(RequestMethod.GET)
      .produces(MediaType.JSON)
      .paged().offset()
      .to(Cars.class).findCarsBy(param("offset"), param("color"), param("limit", "10"));
@danbev
danbev / gist:4555903
Last active December 11, 2015 05:58
Paging in Route Configuration
final RoutingModule routingModule = new AbstractRoutingModule() {
    @Override
    public void configuration() {
      route()
            .from("/cars")
            .on(RequestMethod.GET)
            .produces(MediaType.JSON, CustomMediaTypeResponder.MEDIA_TYPE)
            .paged().totalCallback("getCarsTotal").headersPrefix("CompayName-")
 .to(Cars.class).findCarsByBrand(param("offset", "0"), param("limit", "10"));
@danbev
danbev / gist:4537431
Last active December 11, 2015 03:28
Pagination in AeroGear

Pagination RESTFul API on AeroGear Controller

This document describes pagination in AeroGear. It defines the metadata passed between the client and server.

Parameters

  • offset
    The offset of the first element that should be included in the returned collection. Default value is 0.
  • limit
    The number of elements that should be returned. Default value is 10
  • total
    The total number of elements available.
@danbev
danbev / gist:4500336
Last active December 10, 2015 22:09
AeroGear Controller Demo Paging Route

AeroGear Controller Demo Paging Route

This page discusses AEROGEAR-795 which is about adding an example to aerogear-controller-demo to demonstrate paging support so that the client libraries (Android, JavaScript, and iOS) can be tested against it.

Use case

The example is using /cars as the resource to interact with.

The following route has been added to the demo:

route()
      .from("/cars")
@danbev
danbev / gist:4451648
Created January 4, 2013 10:56
Path param issue in AeroGear Controller Demo

Path Param with include issue

This gist concerns AEROGEAR-732.

Problem Description

The problem was discovered by Sebastian how needed to use a path parameter for a view in AeroGear Controller. The view in question was simple jsp page that displayed information about a user which is part of an admin section of aerogear-controller-demo. The idea is that when logged in as an administrator you can register and manage users.

To access information about a user you follow a link, for example:

<div class="sixteen columns">
    <table style="border: 1;border-color: gray; border-style: solid">
@danbev
danbev / gist:4441337
Last active December 10, 2015 13:29
JSON Response for Error Routes

JSON Responses for Error Routes

We recently added support for routes to be able to produce responses, other than original MVC forwarding to a view. This addition meant that a route could specify the media types it produces, and a client could specify the desired media types using the HTTP Accept header, and get back a response body with that type.
But this only worked for normal routes and not for error routes which is what AEROGEAR-515 has added.

You can now specify that your error routes produce different types:

route()
      .on(Exception.class)
      .produces("text/html", "application/json")
 .to(Error.class).index(param(Exception.class));
@danbev
danbev / gist:4353171
Created December 21, 2012 14:32
HTML View Responder

I'm working on AEROGEAR-693 and trying to figure out how to implement this in the best way.

At the moment, the default type of ViewResponder is the MvcResponder which forwards to a JSP page. By default, this means that if you do not specify a produces() method on a route, this is what you'll get.

Now, the media types that are passed to the produces() method determine two things:

  1. How to match to Route that is the target of a request, matching the HTTP Accept header.
  2. Determining the ViewResponder to be used.

The issue here is that for both a HTMLResponder and a JSPResponder the media type would in both cases be text/html.
How do we determine which one the users actually has created a view for (jsp or html page)?

@danbev
danbev / gist:4344933
Last active December 9, 2015 23:29
Accept '*/* media type

In aerogear-controller we have support for specifying what media type that a route produces:

route()
    .from("/car/{id}")
    .on(RequestMethod.GET)
    .produces(MediaType.HTML, MediaType.JSON)
    .to(SampleController.class).find(param("id"));
}