Simple micro web framework written in Pragmatic Functional Java style

Overview

Pragmatica REST Example

Example nano web framework written in Pragmatic Functional Java style.

Example

public class App {
    public static void main(final String[] args) {
        WebServer.create(
            //Full description
            from("/hello").get().text().with(request -> success("Hello world")),

            //Default content type (text)
            from("/hello").get().with(request -> success("Hello world: " + request.bodyAsString())),

            //Shortcut for method, explicit content type
            get("/getbody").text().with(request -> success("What is this? " + request.bodyAsString())),

            //Shortcut for method, default content type
            get("/getbody").with(request -> success("What is this? " + request.bodyAsString())),

            //Error handling
            //a) Runtime exception handling example
            get("/boom").with(request -> {
                throw new RuntimeException("Some exception message");
            }),
            //b) Return error
            get("/boom2").with(request -> failure(WebError.UNPROCESSABLE_ENTITY)),

            //Nested routes
            from("/v1",
                from(
                    "/user",
                    get("/list").json().with(request -> success(request.pathParams())),
                    get("/query").json().with(request -> success(request.queryParams())),
                    get("/profile").json().with(request -> success(new UserProfile("John", "Doe", "[email protected]")))
                )
            )
        )
        .start()
        .join();
    }
}
You might also like...

Simple Calender App Written in Java , Built with Gradle

Simple Calender App Written in Java , Built with Gradle

Simple Calendar Simple Calendar is an just another open-source Android Calendar application written in java. Features Minimal & Clean Fullfilles needs

Dec 3, 2021

The project is a simple vulnerability Demo environment written by SpringBoot

The project is a simple vulnerability Demo environment written by SpringBoot

The project is a simple vulnerability Demo environment written by SpringBoot. Here, I deliberately wrote a vulnerability environment where there are arbitrary file uploads, and then use the `scan` attribute in the loghack configuration file to cooperate with the logback vulnerability to implement RCE.

Dec 14, 2022

Simple and lightweight application which is checking status of your web services and send a notification if it is down.

rose-uptimer Simple and lightweight application which is checking status of your web services and send a notification if it is down. Example configura

Sep 25, 2022

Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based system

FRC 2022 Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based s

Oct 4, 2022

Lattice is a powerful, lightweight business extension invoke framework. By using the Lattice framework, complex business customization can be efficiently organized and managed.

Lattice Framework Introduction Lattice is a powerful, lightweight business extension invoke framework. By using the Lattice framework, complex busines

Dec 30, 2022

a simple mini-project using Spring framework

Room Reservation Service First attempts to learn Spring with Linkedin-Learning led me to create this mini-project; a simple room reservation service f

Sep 23, 2021

A simple and scalable Android bot emulation framework, as presented at Black Hat Europe 2021's Arsenal, as well as atHack 2021's Arsenal

m3 A simple and scalable Android bot emulation framework. A detailed explanation can be found here. This project was first published at Black Hat Euro

Aug 20, 2022

This project is a simple messaging application made using React-Native framework, Gifted-Chat library and Firebase database

This project is a simple messaging application made using React-Native framework, Gifted-Chat library and Firebase database. The example that will be shown here focuses on the ability of two people to message each other in a chat room.

Jan 30, 2022

Creational design patterns written in Java

Java Design Patterns Creational design patterns implementation: Singleton, Factory Method, Builder written in Java. Getting Started No additional step

Mar 7, 2022
Owner
Sergiy Yevtushenko
Sergiy Yevtushenko
This project archetype is a template for creating a fully functional MVC web application using Hibernate, JSTL and Bootstrap

This project archetype is a template for creating a fully functional MVC web application using Hibernate, JSTL and Bootstrap. It has an automatic database creation, auto initial load of the data, with different variety of users. It also has a checkstyle to check the proper coding of your project immediately right after you enter the code.

null 90 Oct 21, 2022
A fast and reliable Java micro-library which chooses the sorting algorithm that best fits your needs and sorts the parameter.

A fast and reliable Java micro-library which chooses the sorting algorithm that best fits your needs and sorts the parameter.

Simone Nicol 2 Feb 19, 2022
Payara Micro & MicroProfile Fundamentals (PMMPF)

Payara Micro & MicroProfile Fundamentals (PMMPF) In this course, you will learn the fundamentals of how to develop modern cloud-native microservices w

null 2 May 3, 2022
LibGDX PSX-style render features

gdx-psx gdx-psx its a library for LibGDX designed to assist you in simulation of PlayStation 1 graphics with few simple steps! If you have questions o

Matvey 27 Dec 10, 2022
LaetLang is an interpreted C style language. It has file reading/writting, TCP network calls and awaitable promises.

LaetLang ?? LaetLang is an interpreted C style language built by following along Robert Nystrom's book Crafting Interpreters. This is a toy language t

Alexander Shevchenko 6 Mar 14, 2022
This repository is related to the Java Web Developer (ND035), Course - Web Services and APIs

About this Repository This repository is related to the Java Web Developer (ND035), Course - Web Services and APIs It contains the following folders:

Rasha Omran 1 Jan 28, 2022
JSON Web Token implementation for Java according to RFC 7519. Easily create, parse and validate JSON Web Tokens using a fluent API.

JWT-Java JSON Web Token library for Java according to RFC 7519. Table of Contents What are JSON Web Tokens? Header Payload Signature Features Supporte

Bastiaan Jansen 6 Jul 10, 2022
A springboot starter for retrofit, and supports many functional feature enhancements, greatly simplifying development

retrofit-spring-boot-starter English Document Retrofit是适用于Android和Java且类型安全的HTTP客户端,其最大的特性的是支持通过接口的方式发起HTTP请求。而spring-boot是使用最广泛的Java开发框架,但是Retrofit官方

Ke Technologies 1.4k Jan 5, 2023
A lazily evaluated, functional, flexible and concise Lisp.

KamilaLisp A lazily evaluated, functional, flexible and concise Lisp modelled after Haskell and APL, among others. ;; Hello, world! (println "Hello, w

Kamila Szewczyk 42 Dec 15, 2022
The application consists of a web page with a list of some movies. The page allows user interaction through ratings of movies listed in the web app.

DSMovie About the project https://matheus-maia-alvarez-dsmovie.netlify.app/ DSMovie is a full stack web and mobile application built during the Spring

Matheus Maia Alvarez 6 Jul 21, 2022