Simple JSP Servlets REST api.

Overview

JSPRestAPI

Simple JSP Servlets REST api.

You can simply add it to your project using

Maven

<repositories>
    <repository>
        <id>jitpack.ioid>
        <url>https://jitpack.iourl>
    repository>
repositories>
<dependency>
    <groupId>com.github.SashaSemenishchevgroupId>
    <artifactId>JSPRestAPIartifactId>
    <version>VERSIONversion>
dependency>

Or Gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.SashaSemenishchev:JSPRestAPI:VERSION'
}

Using it

@WebServlet(name = "helloServlet", urlPatterns = "/hello")
public class HelloServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("application/json"); // VERY IMPORTANT
        response.setStatus(200); // Status for response. 200 - OK, 400 - Bad Request, 404 - Not Found etc.
        RESTApi.returnResponse(response, "{\"some_data\": \"another_data\"}");
    }
}

Or

data = new HashMap<>(); data.put("some_data", "another_data"); response.setStatus(400) // Status for response. 200 - OK, 400 - Bad Request, 404 - Not Found etc. RESTApi.returnResponse(response, new JSONObject(data)); } } ">
@WebServlet(name = "helloServlet", urlPatterns = "/hello")
public class HelloServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("application/json"); // VERY IMPORTANT
        HashMap<String, String> data = new HashMap<>();
        data.put("some_data", "another_data");
        response.setStatus(400) // Status for response. 200 - OK, 400 - Bad Request, 404 - Not Found etc.
        RESTApi.returnResponse(response, new JSONObject(data)); 
    }
}

As you can see, this API using Google JSONSimple. Dependency provides it.

Some docs

RESTApi.returnResponse(response, jsonObject);

Response is HttpServletResponse from your servlet doGet or doPost etc.
jsonObject is JSONObject from JSONSimple. See tutorials about JSONSimple.

RESTApi.returnResponse(response, jsonString);

Difference between previous method is jsonString, not jsonObject. jsonString is String as json. (P.S string is checks by parser, so don't worry about you entered wrong string)

Still need help? Join our discord.

We support en and ru users https://discord.gg/kGcUgA3JP8

You might also like...

绕过安卓hidden api 限制

背景 非 SDK API 名单(谷歌官方) 随着每个 Android 版本的发布,会有更多非 SDK 接口受到限制。 我们知道这些限制会影响您的发布工作流,同时我们希望确保您拥有相关工具来检测非 SDK 接口的使用情况、有机会向我们提供反馈,并且有时间根据相应新政策做出规划和调整。 为最大程度地降低

Nov 29, 2022

Disable the 1.8x Click delay with this sleek API.

Tecknix Client Click Delay API A simple solution to remove Minecraft 1.8's click delay timer. Installation: Tecknix Click Delay API requires a Bukkit

Nov 16, 2021

API de Clientes - Java+Quarkus

com.clientes.api Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its

Oct 12, 2021

API RESTful Challenge

developer-challenge API RESTful Challenge API feita com java e hospedada no Heroku #Adicionar país Metodo: [POST] https://challenge-rest-api.herokuapp

Sep 7, 2022

An easy to use api to interact with many versions of minecraft in a version independent environment.

Glass - API An easy to use api to interact with many versions of minecraft in a version independent environment. Setup Instructions should be relative

Jan 25, 2022

API - Aprendizagem por Projetos Integrados

API - Aprendizagem por Projetos Integrados Participantes Nome Função GitHub Everton Ricardo Wanderley da Rocha Product Owner Gustavo Konflanz Mezzomo

Apr 15, 2022

A damn simple library for building production-ready RESTful web services.

Dropwizard Dropwizard is a sneaky way of making fast Java web applications. It's a little bit of opinionated glue code which bangs together a set of l

Jan 5, 2023

Rapidoid - Extremely Fast, Simple and Powerful Java Web Framework and HTTP Server!

Rapidoid - Simple. Powerful. Secure. Fast! Rapidoid is an extremely fast HTTP server and modern Java web framework / application container, with a str

Dec 30, 2022
Owner
MisterFunny01
MisterFunny01
Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API

Swagger Core NOTE: If you're looking for Swagger Core 1.5.X and OpenAPI 2.0, please refer to 1.5 branch. NOTE: Since version 2.1.7 Swagger Core suppor

Swagger 7.1k Jan 5, 2023
Leading REST API framework for Java

Restlet Framework The leading REST API framework for Java Thanks to Restlet Framework's powerful routing and filtering capabilities, unified client an

Restlet Framework 633 Dec 18, 2022
Microserver is a Java 8 native, zero configuration, standards based, battle hardened library to run Java Rest Microservices via a standard Java main class. Supporting pure Microservice or Micro-monolith styles.

Microserver A convenient modular engine for Microservices. Microserver plugins offer seamless integration with Spring (core), Jersey, Guava, Tomcat, G

AOL 936 Dec 19, 2022
Spring HATEOAS - Library to support implementing representations for hyper-text driven REST web services.

Spring HATEOAS This project provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and es

Spring 996 Dec 28, 2022
Spring HATEOAS - Library to support implementing representations for hyper-text driven REST web services.

Spring HATEOAS This project provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and es

Spring 920 Mar 8, 2021
RestAhead - compile time generated REST client

RestAhead - compile time generated REST client This project draws inspiration from projects such as Retrofit and Feign, but with a twist: your service

Žan Skamljič 13 Dec 24, 2022
A Java API wrapper for the pastemyst api

Pastemyst.java What is pastemyst.java? pastemyst.java is a pastemyst API Wrapper, written in Java. The library is in early development, and all contri

YeffyCodeGit 8 Sep 28, 2022
Dio-api-1 - Repositório com os artefatos da mentoria de API

dio-api-1 Repositório com os artefatos da mentoria de API Reference Documentation For further reference, please consider the following sections: Offic

Ricardo Lucas Chagas 5 Feb 25, 2022
API Gestor é uma API que permite a comunicação com um Banco de Dados educacionais sobre a educação brasileira.

API Gestor O projeto API Gestor é uma API que permite a comunicação de outras aplicações com os dados educacionais armazenados em um banco de dados, c

null 2 Apr 13, 2022
A simple API wrapper for discords.com (alias botsfordiscord.com) written in Java.

Discords.com / BotsForDiscord.com Java Library A simple API wrapper for discords.com (alias botsfordiscord.com) written in Java 8. Installation This w

Dorian 3 Aug 6, 2021