Skip to content

vanbv/num

Repository files navigation

Maven License Language

num

num (Netty URL Mapping) is a Java library that adds request mapping to the Netty library.

Getting Started

Add dependency to start using num library:

compile group: 'com.github.vanbv', name: 'num', version: '0.0.3', ext: 'jar'

Besides num library you need to add Netty library to the project.

Guide

To handle a request, you must create a handler class. This class will handle incoming http requests to the server. For that end you need to extends class AbstractHttpMappingHandler, create the method that returns FullHttpResponse and annotate it as:

  • @Get
  • @Post
  • @Put
  • @Delete

Only GET, POST, PUT and DELETE requests are supported now.

It is necessary to specify the URL-address in the value parameter of the annotation. The method is called referring to URL-address.

@Get("/test/get")
public DefaultFullHttpResponse get() {
…
}

You can use annotations to pass parameters in methods:

  • @PathParam - for path parameters
@Get("/test/get/{message}")
public DefaultFullHttpResponse get(@PathParam(value = "message") String message) {
…
}
  • @QueryParam - for query parameters
@Get("/test/get")
public DefaultFullHttpResponse get(@QueryParam(value = "message") String message) {
…
}
  • @RequestBody - for POST requests body. It is allowed to use only in POST requests.
@Post("test/post")
public DefaultFullHttpResponse post(@RequestBody Message message) String message) {
…
}

To use @RequestBody, you must pass the implementation of theJsonParser interface, which parses data from the request body, to the constructor of the handler class. The library already has a default implementation of JsonParserDefault. The implementation uses a jackson parser. Therefore, if you use this implementation you must add a dependency com.fasterxml.jackson.core:jackson-databind to the project.

Demo

You can look at a demonstration of the use of num library in the project.

License

Licensed under the Apache License, Version 2.0.

About

Netty URL Mapping

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages