# Read and write to REST-enabled databases

Once development teams begin using Postman to test their APIs, a logical follow-up question is how Postman can interact with databases. Postman can interact with any available HTTP endpoint, including REST-enabled database endpoints. Instead of querying a database directly, developers and testers use Postman to read and write to a database via a REST API. **[![](https://blog.postman.com/wp-content/uploads/2018/02/restdb.png)](https://blog.postman.com/wp-content/uploads/2018/02/restdb.png)** **Why would you want to do this?** During development when you’re working with a local version of your database, you can use Postman to read and write to your database and make assertions about those responses. In this manner, you can test the internal state of your database that isn’t exposed by your API. Furthermore, using Postman can be a faster way to learn and use the database for someone who's unfamiliar with SQL. There are 2 ways to access your database using Postman:1. You can start a local database server, use scripts in Postman to build a request to send to that server, and log entries in a local instance of a database, kind of like how you would [write to your local file system](https://blog.postman.com/2017/09/01/write-to-your-local-file-system-using-a-postman-collection/).
2. Additionally, many database providers, like MySQL, MS SQL, and Mongo, provide an HTTP API to access their databases.
 
 In this example, we’ll take the second approach, walk through how to set up a database using [Restdb.io](https://restdb.io/), and then access the database using Postman.### **Setting up the database in Restdb.io**

 In their [quick start guide](https://restdb.io/docs/quick-start), Restdb.io walks through setting up a database, creating a restdb.io collection (an abstraction similar to a database table), and adding fields to the collection.  Once our database is set up, we will have a unique URL as its main access point, such as `https://example-5a1e.restdb.io`, that we’ll need for the next step. In this example, I’ve created a restdb.io collection called `contact` and entered some records containing fields like `name`, `email`, and `photo`. [![](https://blog.postman.com/wp-content/uploads/2018/02/image1.png)](https://blog.postman.com/wp-content/uploads/2018/02/image1.png)### **Setting up Postman to hit the database**

 In the Postman app, enter the URL from the previous step into the request builder. If you’re going to be switching between with different server environments or databases, consider swapping out path elements for [environment variables](https://learning.postman.com/docs/postman/variables-and-environments/managing-environments/#creating-a-new-environment) using a double curly brace syntax. The full URL should look something like this: `<main-access-point>/rest/<collection-name>`.[![](https://blog.postman.com/wp-content/uploads/2018/02/image3.png)](https://blog.postman.com/wp-content/uploads/2018/02/image3.png) Under the **Headers** tab, specify your `Content-Type` as `application/json`. Still under the **Headers** tab, add your `x-apikey` along with the value of your restdb.io key from their Users and Settings page for the database. In Postman, you can paste the key directly in the field, or store it as an [environment variable](https://learning.postman.com/docs/postman/variables-and-environments/managing-environments/#creating-a-new-environment) like we did in the first step.[![](https://blog.postman.com/wp-content/uploads/2018/02/image4.png)](https://blog.postman.com/wp-content/uploads/2018/02/image4.png)### **Read, Write, and Test**

 Now, Postman is ready to send a request to your database. Hit **Send** and inspect the database API's response. [![](https://blog.postman.com/wp-content/uploads/2018/02/image2.png)](https://blog.postman.com/wp-content/uploads/2018/02/image2.png) Just like testing your API to ensure responses are successful and as we would expect, we can [add some tests](https://blog.postman.com/2017/10/25/writing-tests-in-postman/) to make assertions about your database responses as well.  For example, if we added a new field called `active`, but didn’t plan to expose it to our users via API, we could test if this new field exists with a database query using Postman.  [![](https://blog.postman.com/wp-content/uploads/2018/02/image5.png)](https://blog.postman.com/wp-content/uploads/2018/02/image5.png)