LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Rest Services Test

Once all modules can be built successfully, we can start the servers and test the todo-list application.

First, we need to make sure Mysql, Zookeeper, Kafka and CDC server for eventuate are up and running.

You can follow this tutorial to start all of them with a docker-compose.

Before we start the rest-command and rest-query, let’s create the database and table for the rest-query material view in the same Mysql database for the event store. We are going to create another database called todo_db. If you are using the networknt/mysql docker image, the table is created already.

Here is the database script and you can use mysql command line or just using any GUI tools to run it against MySQL server.

create database todo_db;

GRANT ALL PRIVILEGES ON todo_db.* TO 'mysqluser' IDENTIFIED BY 'mysqlpw';

use todo_db;

DROP table IF EXISTS  TODO;


CREATE  TABLE TODO (
  ID varchar(255),
  TITLE varchar(255),
  COMPLETED BOOLEAN,
  ORDER_ID INTEGER,
  ACTIVE_FLG varchar(1) DEFAULT 'Y',
  PRIMARY KEY(ID)
);

Remember that MySQL root user and password as follows.

dbUser: root
dbPass: rootpassword

Now let’s start rest-command service

cd ~/networknt/light-example-4j/eventuate/todo-list/rest-command
java -jar target/rest-command-1.0.0.jar

Now let’s start rest-query service

cd ~/networknt/light-example-4j/eventuate/todo-list/rest-query
java -jar target/rest-query-1.0.0.jar

Let’s create a todo item with curl

curl -k -X POST \
  https://localhost:8081/v1/todos \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{"title":"this is the test todo from postman","completed":false,"order":0}'

And the response will be

{
    "cancelled": false,
    "done": true,
    "completedExceptionally": false,
    "numberOfDependents": 0
}

This request will send a request which will call back-end service to generate a “create todo” event and publish to event store.

Event sourcing system will save the event into event store.

CDC service will be triggered and will publish the event to Kafka:

The request publishes a “CreateTodo” event and will save the entity/event to the event store MySQL database.

We can use mysql command line tool to verify:

select * from entity;

select * from events;

Now let’s access the rest-query service

curl -k -X GET https://localhost:8082/v1/todos

And the response will be something like this.

[
    {
        "0000015d968eacee-0e23a9398a990001": {
            "title": "this is the test todo from postman",
            "completed": false,
            "order": 0
        }
    },
    {
        "0000015d968f5443-0e23a9398a990001": {
            "title": "this is the test todo from postman",
            "completed": false,
            "order": 0
        }
    },
    {
        "0000015d969d6ce2-0e23a9398a990001": {
            "title": "this is the test todo from postman",
            "completed": false,
            "order": 0
        }
    }
]

Event sourcing system will subscribe the events from event store and process the events by user-defined event handlers.

For todo-list example, the event handler simply gets the event and save the latest todo info into local TODO table.

In the next step, we are going to implement a hybrid command side with the light-hybrid-4j framework.

  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Rest Services Test” was last updated: April 2, 2019: fixes #62 add Chinese language for the document site (5c820aa)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute