Simple REST Server

In this tutorial, we will build a an incredibly simple REST Server. GreenLightning is built with REST as a first-class feature; this guide will demonstrate how quickly you can build a simple API that's performant and robust.

Hello World Server

For our tutorial, we will build a very simple API to post to and receive messages back.

We want to develop a server that can do the following:

  • Allow someone to send a GET request with their name in the query and receive a response

  • Post a JSON message to an endpoint and receive a modified response

For the sake of simplicity, this project lacks authentication or even proper validation. In a real application, you definitely don't want this.

Let's see what our 2 simple endpoints will look like:

Say Hello

GET http://localhost/api/hello/${NAME}

Returns a plaintext message containing the name.

Path Parameters

Name
Type
Description

name

string

Name to be returned.

Response
Hello World, ${NAME}!

Post Information About Yourself

POST http://localhost/api/about

Returns a JSON message with the posted JSON slightly modified. Below in the request tab, the parameters should be formatted as JSON as demonstrated in the response.

Request Body

Name
Type
Description

Money

string

JSON key

Age

integer

JSON key

Name

string

JSON key

Response
{
    "msg": "We made Tobi 10 years older and $5000 richer.",
    "money": 6000,
    "age": 30,
    "name": "Tobi",
}

Seems simple enough, right? On the next page, you will learn how to setup your project.

Last updated