Coder Social home page Coder Social logo

minirest's Introduction

MiniREST

This application aims to be a simple mapping between the URL and the handlers registered in the central RequestHandlerOrchestrator class. The usage of this library isn't necessarily bound only to REST. HTTP methods are not part of this handler class, thus the handler itself should be able to handle every expected HTTP method type.

Usage

The RequestHandlerOrchestrator<T> class can be created with or without a preceding path. If the path is set, it will only accept URLs starting with it (e.g. new RequestHandlerOrchestrator("/test") will accept /test/app as a path, but wont accept /app.

After creating the RequestHandlerOrchestrator<T> instance, the handlers for a given path can be entered via the public void setHandler(String handlerUrl, T handler) method. The handlerUrl follows the JAX-RS notation of URL, where the names of the parameters can be entered by using {}; for example /path/{firstParam}/followingpath/{secondParam}. This URL is compiled into a regular expression. Only the following groupMembers are recognized: [a-zA-Z0-9]. Custom regular expressions are currently not supported. When entering a path for parsing, empty parameter names are possible by adding two slashes. E.g. using the previous path: /path//followingpath/secondValue.

The handler cen be received via RequestHandlerOrchestrator.getHandler(String url) method, which returns an Optional<HandlerData<T>>. The HandlerData offers two methods to acquire the handler itself, and the parsed parameters in form of a Map<String, String>.

Query strings are also parsed and put into the final map of parameters. Should duplicate parameters occure in the query string and in the URL, the URL overrides the ones in the query string.

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.