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
  1. Chapter 1: Getting Started with GreenLightning
  2. Simple REST Server

Structures and Fields

In order to reference fields and re-use them, GreenLightning convention specifies to use enums for the field type (although any other object could work as well).

The same idea is applied to routes, which are referred to structures inside GreenLighting. To reference a route, we can simply use the enum.

For this tutorial, we need to have two different enums: HelloField, which will contain the fields we are expecting, and HelloStruct, which references the two different routes we have.

Edit two files named HelloField and HelloStruct the following content:

HelloFields.java
package com.ociweb;

public enum HelloField {
    NAME, MONEY, AGE
}
HelloStruct.java
package com.ociweb

public enum HelloStruct {
    HELLO_WORLD, ABOUT
}

The errors from before should now disappear.

On the next page, we will start creating our behaviors and the core logic of our REST API.

PreviousGetting StartedNextSaying Hello

Last updated 6 years ago