Giter Club home page Giter Club logo

akka-http-ext-controller's Introduction

akka-http-ext-controller

creating controllers with akka-http easily

Supports the http verbs: @GET, @POST, @PUT, @DELETE. Also can handle json body or/and path params.

Prerequisities

  • akka-http-core
  • akka-http-jackson
  • java 1.8

Getting Started

  1. Add maven dependency in your project:

    todo akka-http-ext-controller 0.0.l
  2. Create controllers in your application:

public class UserController {

	@GET
	@Path("users/:id/details")
	public Route details(String id) {
		// getting pathParams
		return Directives.complete("Showing details for user " + id);
	}

	@POST
	@Path("users")
	public Route save(User user) {
		// parsing json body
		return Directives.complete("Saving user " + user.getName());
	}
}
  1. Register your controllers with the Routes.init(ActorSystem, port, controllers...), as follows:
system = ActorSystem.create();
Routes.init(system, 8080, new UserController());

Please note that all controllers must be declared at once (In the same Routes.init call).

  1. Done! You can access your controller at http://localhost:8080/users/1/details

Framework conventions:

All actions must have:

  1. annotation to indicate the http verb
  2. annotation @Path to indicate the path of action
  3. return a akka.http.javadsl.server.Route object, usually you will use akka.http.javadsl.server.Directives for this.

using PathParams

When you use pathParams, the framework inject the arguments in the same order as received, for example: For @Path("user/:id/purchases/:purchaseId/items/:itemId/details") must have a controller with 3 String arguments like this public Route details(String id, String purchaseId, String itemId)

using JSON Body

When you use json body, the framework will try convert body content to object. An action in controller must receive a object, for example public Route update(User user). An error 500 will raise if parse fails.

using QueryString

TODO

Running the tests

$ mvn test

Task List

  • add support to pathParams
  • add support to json body
  • add artifacts to the Central Repository
  • add support to queryString
  • add support to pathParams, json body and queryString when used in same time
  • create annotation @Controller and make package scan to register controllers
  • create annotation @Produces to use with custom content-types like application/vnd.api+json

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

akka-http-ext-controller's People

Contributors

nadilsons avatar

Watchers

windqdu avatar

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.