DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Get Your REST Backend Rolling in 5 Minutes...With Zero Lines of Code!

How to Get Your REST Backend Rolling in 5 Minutes...With Zero Lines of Code!

Learn how you can use UltraESB-X with JPA/Hibernate to integrate your application's frontend and data model to transform user actions into datastore operations.

Janaka Bandara user avatar by
Janaka Bandara
·
Dec. 11, 17 · Tutorial
Like (3)
Save
Tweet
Share
7.78K Views

Join the DZone community and get the full member experience.

Join For Free

The app is finally taking shape. Data is sitting in your datastore. Users are about to start bombarding the front-end with requests. Quite a familiar scenario for any standard web/mobile app developer.

You have approached the Big Question: How to get the ball rolling? How to transform user actions into actual backend datastore operations?

One (obvious) way would be to build an ORM, configure a persistence provider (such as Hibernate-JPA), and link the pieces together through an MVC-style contraption.

But what if you don't want all those bells and whistles? Or, what if all you need is just a quick 'n dirty PoC to impress your client/team/boss, while you are struggling to get the real thing rolling?

Either way, what you need is the "glue" between the frontend and the data model, or "integration" in more techy jargon.

UltraESB-X, the successor of the record-breaking UltraESB, is an ideal candidate for both your requirements. Being a standalone yet lean runtime—just 9 MB in size, and runnable with well below 100 MB of heap—you could easily deploy one in your own dev machine, prod server, cloud VM, Docker, or on IPS, the dedicated lifecycle manager for on-premise and (coming up) cloud deployments.

As if that wasn't enough, building your backend becomes a simple drag-and-drop game, with the cool UltraStudio IDE for integration project development. Just pick the pieces, wire them together under a set of integration flows—one per each of your workflows, with interleaving subflows where necessary—and have your entire backend tested, verified and ready for deployment within minutes.

We have internally used UltraESB-X seamlessly with JPA/Hibernate, whose details we hope to publish soon—in fact, there's nothing much to publish, because it all just works out of the box, thanks to the Spring-driven Project-X engine powering the beast.

That being said, all you need right now is that QnD solution to wow your boss, right?

That's where the JSON Data Service utility comes into play.

Tiny as it may seem, the JSON Data Service is a powerful REST-to-CRUD mapper. It simply maps incoming REST API requests into SQL, executing them against a configured database and returning the results as JSON. Exactly what you need for a quick PoC or demo of your app!

We have a simple yet detailed sample demonstrating how to use the mapper, but all in all it's just a matter of specifying a set of path-to-query mappings. The queries can utilize HTTP path and query parameters to obtain inputs. SQL column name aliases can be used to control what fields would be returned in the response. The HTTP method of the inbound request (GET, POST, PUT, DELETE) decides what type of operation (create, read, update, delete) would be invoked. Of course, you can achieve further customization (adding/modifying fields, transforming the result to a different format such as XML, as well as audit actions such as logging the request) by simply enhancing the integration flow before the response is returned to the caller.

For example, here are some REST API operations, with their corresponding JSON Data Service configurations (all of which could be merged into a single integration flow, to share aspects like authentication and rate limiting):

Assuming

  • a book  API entity to be returned to the frontend:
{
"name": "book_name",
"author": "author_name",
"category": "category_name"
}

    • a BOOK  table:
    (
    ID SMALLINT,
    NAME VARCHAR(25),
    AUTHOR_ID SMALLINT,
    CATEGORY VARCHAR(25)
    )

    • and an associated AUTHOR  table:
    (
    ID SMALLINT,
    NAME VARCHAR(25)
    )
  • The following API endpoints:

    GET /books?start={offset}&limit={count}

    return all books, with pagination (not including author details)

    GET /books/{id}

    return a specific book by ID, with author details

    GET /books/search?author={author}

    return all books of a given author


    Could be set up with just the following data service configuration mapping (the rest of the steps being identical to those in our dedicated sample; just ensure that you maintain the order, and note the extra SINGLE: in front of the 2nd query):

    /books/search?author={author:VARCHAR} SELECT B.NAME AS name, B.CATEGORY AS category
        FROM BOOK B, AUTHOR A
        WHERE B.AUTHOR_ID = A.ID AND A.NAME = :author
    /books/{id:INTEGER} SINGLE: SELECT B.NAME AS name, A.NAME AS author, B.CATEGORY AS category
        FROM BOOK B, AUTHOR A
        WHERE B.AUTHOR_ID = A.ID AND B.ID = :id
    /books?start={offset:INTEGER}&limit={count:INTEGER} SELECT NAME AS name, CATEGORY AS category
        FROM BOOK LIMIT :offset, :count


    On top of a graphical, drag-drop-and-connect flow that is as simple as:

    Project-X JSON Data Service sample flow

    See? Anybody with a basic SQL knowledge can now set up a fairly complex REST API, without writing a single line of code, thanks to Project-X and the JSON Data Service!

    REST Web Protocols Database

    Opinions expressed by DZone contributors are their own.

    Popular on DZone

    • Spring Cloud: How To Deal With Microservice Configuration (Part 1)
    • Top Authentication Trends to Watch Out for in 2023
    • Automated Performance Testing With ArgoCD and Iter8
    • Connecting Your Devs' Work to the Business

    Comments

    Partner Resources

    X

    ABOUT US

    • About DZone
    • Send feedback
    • Careers
    • Sitemap

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 600 Park Offices Drive
    • Suite 300
    • Durham, NC 27709
    • support@dzone.com
    • +1 (919) 678-0300

    Let's be friends: