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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building a REST Application With Oracle NoSQL Using Helidon
  • Getting Started With Boot Spring 3.2.0: Building a Hello World REST API With NoSQL Integration
  • Securing REST APIs With Nest.js: A Step-by-Step Guide
  • Leveraging Query Parameters for Efficient Data Filtering in REST APIs

Trending

  • The SDLC After AI
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL
  • One Database, Two Models: Building AI-Friendly Java Applications With MySQL JSON Duality Views
  • LangChainGo vs Genkit Go: Where Genkit Shines

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Expose Your Database as a REST API Safely and Without Code

Expose Your Database as a REST API Safely and Without Code

DB2Rest is open-source middleware that offers a no-code way to safely expose data from your database for your applications to consume.

By 
Thad Guidry
·
Updated by 
Dhrubo Kayal
·
Apr. 30, 24 · Review
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
3.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

One of the complex parts of application development is to first write code to connect to your database and then try to leverage an Object Relational Mapping (ORM) framework to help write your data access layer.

But what would things look like if you did not need an ORM? Or did not need to write a data access code to access your database? How would you then expose the data AND access it safely for your front-end application development?

REST APIs provide a standardized interface to use HTTP requests to return data to users or applications in the form of JSON, HTML, XML, etc.

We can use some middleware to sit between our database and our application. We can then use RESTful queries in our application to ask the middleware to give us the specific data filtered to our liking as needed for our applications' operations. But which middleware? And wouldn't something in the middle slow things down?

Simple

DB2Rest is open-source middleware that offers a no-code way to safely expose data from your database for your applications to consume. It runs as a service that you can host locally or in the cloud. It even has an easy-to-use Docker deployment.

Let's see a simple example of a query with DB2Rest that shows how to filter on our database table of "movies".

QUERY

http GET 'http://example.com/movies?filter=title=="Titanic";year=gt=1950' 
User-Agent:insomnia/8.6.1


RESULT

HTTP/1.1 200 Content-Type: application/json Transfer-Encoding: chunked 
[  {    "title": "Titanic",    "year": 1953,    "distributor": "20th Century Fox",    "budget": "$1,805,000",    "director": "Jean Negulesco"  },  {    "title": "Titanic",    "year": 1997,    "distributor": "Paramount Pictures",    "budget": "$200,000,000",    "director": "James Cameron"  } ]


Notice the QUERY where we didn't even need to use a full SQL query!?!

We simply asked to filter by a title and the year greater than 1950.

year=gt=1950


And it easily returned results!

DB2Rest uses simple syntax (based on RQL — those keywords within = equal signs) for querying and even updating, deleting, and joining tables.

Fast

DB2Rest is blazing fast even as middleware and is reported by users since it doesn't need to use an ORM, but instead uses industry-proven data access libraries and drivers for the most common databases. The queries are even cached for greater speed. DB2Rest translates your queries without code generation! into SQL so you don't have to, forward to the database, and return paginated results in JSON. If you already know SQL, DB2Rest can also just forward any custom SQL expressions to your database.

This is really great because with DB2Rest you can even expose legacy databases to your applications without all the pain of coding, and quickly take advantage of that older data, or even skip database migrations and just use DB2Rest to give data access to your legacy data!

Secure

What is even better, I think, is that DB2Rest can serve as a gateway of sorts by being middleware and not directly exposing your database to your users or application, but instead only the data it needs. There's not even a possibility of SQL Injection attacks because of this. Security concerns are further minimized by configuring DB2Rest to use a DB user account that only has access to the schema and tables you wish to give access to. All data access security is thus handled directly by your database user access roles (and not DB2Rest) to conform with best practices and allow database administrators (DBAs) to continue to maintain security access roles as they need, even in an enterprise setting. Or your own movie or bread recipe database. :-)

API Data access Database REST Middleware

Published at DZone with permission of Thad Guidry. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building a REST Application With Oracle NoSQL Using Helidon
  • Getting Started With Boot Spring 3.2.0: Building a Hello World REST API With NoSQL Integration
  • Securing REST APIs With Nest.js: A Step-by-Step Guide
  • Leveraging Query Parameters for Efficient Data Filtering in REST APIs

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook