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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

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

  • Infrastructure as Code (IaC) Beyond the Basics
  • Memory Leak Due to Time-Taking finalize() Method
  • Integrating Model Context Protocol (MCP) With Microsoft Copilot Studio AI Agents
  • The Full-Stack Developer's Blind Spot: Why Data Cleansing Shouldn't Be an Afterthought
  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 user avatar
Thad Guidry
·
Updated by 
Dhrubo Kayal user avatar
Dhrubo Kayal
·
Apr. 30, 24 · Review
Likes (2)
Comment
Save
Tweet
Share
2.0K Views

Join the DZone community and get the full member experience.

Join For Free

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
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!