Converting a Spring Boot Service To Ballerina

  • Student record lookup returns a JSON student representation with HTTP 200 OK or an HTTP 404 Not Found if the record is not there.
  • Student record insertion returns a HTTP 200 OK or else if the record is already there, should return an HTTP 400 Bad Request.
  • Student record update returns HTTP 200 OK on success, or else, if the record is already there, should return an HTTP 400 Bad Request.
  • Student record delete will remove the record if it exists, and will always return HTTP 200 OK.
  • The student insertion and update schema must be validated, and the request should fail for an invalid input. The student “major” field is an enumeration with three values: “CS”, “Physics”, and “Chemistry”, and it has the default value “CS”.

Spring Boot Implementation

build.gradle

Application

https://gist.github.com/lafernando/8ec0ea1f1b9dcf1d76669c7f3079e883Application.java

Student

Student.java

StudentRegistryController

StudentRegistryController.java

Running the Service

Student Registry Spring Boot Application Startup

Ballerina Implementation

student_registry.bal

Resource Model Representation

Application and REST Controller

Graphical View

VS Code — Generated Sequence Diagram for “lookupStudent” Resource

Summary

Author of ‘Beginning Ballerina Programming’ | Software Developer | Evangelist | 🇱🇰 🇺🇸 | Working at WSO2 Inc. — @lafernando

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kyve : How to run a node (pool Zilliqa)

What are GET & POST requests in Python?

try! Swift India-2017 | An Amazing Experience

Symfony perfect entity, dates and data

Where to Spend Your Time Now that You’re Done with Your Coding Bootcamp

Main Menu Scene

Why a father and techie decided to mentor and train others

Terraform best practices — using a consistent naming convention

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anjana Fernando

Anjana Fernando

Author of ‘Beginning Ballerina Programming’ | Software Developer | Evangelist | 🇱🇰 🇺🇸 | Working at WSO2 Inc. — @lafernando

More from Medium

Spring Boot Framework

Spring boot

Spring Boot Microservices — Part4 — OpenFeign

Writing REST API with OpenAPI and SpringBoot