GreenLightning
  • GreenLightning
  • Chapter 0: What is Green Lightning?
    • Downloads
    • FAQs
    • Benchmarks
  • Chapter 1: Getting Started with GreenLightning
    • What you need
    • Simple REST Server
      • Getting Started
      • Structures and Fields
      • Saying Hello
      • Posting and Responding with JSON
    • Comprehensive Start Guide
  • Chapter 2: Configuration
    • HTTP Configuration
    • MQTT Configuration
    • TLS Certificates
  • Chapter 3: Listeners and Behaviors
    • Default Listeners
    • Blocking Behaviors
  • Chapter 4: Routes
    • Basic Routing
  • Chapter 5: PubSub
    • Publish & Subscribe
  • Chapter 6: Clients
    • HTTP Client
    • MQTT Client
Powered by GitBook
On this page
  • Hello World Server
  • Say Hello
  • Post Information About Yourself
  1. Chapter 1: Getting Started with GreenLightning

Simple REST Server

PreviousWhat you needNextGetting Started

Last updated 6 years ago

In this tutorial, we will build a an incredibly simple 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.

REST