A Better Developer Experience with the MongoDB Atlas Data API


This is a guest post written by Joel Lord, developer advocate at MongoDB.

MongoDB started off as a general-purpose NoSQL database back in 2009. Over the years, the product evolved into much more than a database. The cloud offering, MongoDB Atlas, provides a collection of services that developers can use to make it easier than ever to build applications. One of these new features is the Atlas Data API, enabling developers who are used to working with REST APIs to connect to their database over a similar interface easily.

Because MongoDB aims to provide the best developer experience possible, it only made sense to help developers connect to the best API testing tool to explore this new API.

The new MongoDB Atlas Data API

MongoDB provides drivers for all the major programming languages and makes it simple for software developers to use a syntax they are familiar with to connect to their database. However, there are cases where those drivers are not enough.

Some programming languages just don’t have a driver available. Bash, for example, doesn’t have one. To write or read from a database, developers need to call a script or an application written in a different language. This requires additional work and creates code that is harder to maintain. Using this new MongoDB Data API, it is now possible to use a `curl` command to interact with data from a collection. For example, this Wordle clone written in Bash reads a random five-letter word from a MongoDB collection to initialize the game. Another everyday use case is with CI/CD pipelines. As part of a pipeline, an engineer might want to persist some information about the latest run in a database.

Another frequent use case is for low-code or no-code applications. If you take a product like Zapier or IFTTT, you can create data flows across various applications. Those platforms can also trigger a REST call to a URL based on specific events. This URL can now be an Atlas Data API endpoint, enabling those platforms to directly write data to a collection without needing a third-party application to relay the information. For example, one could write an entry into a MongoDB collection each time their cat uses their litter box, using some of the IFTTT integrations. This could make it easier to track your cat’s health.

While using the Data API with IFTTT to track cat litter might not be everyone’s top priority, the same simple setup holds true for every low-code or no-code tool you might use with the Data API, including business-centric tools like GitHub or Jira with Zapier.

A screenshot of Zapier showing a zap triggered by Gihub to make a web request to Atlas
A Zapier zap that would write to MongoDB Atlas each time a pull request is created, and then create an issue in Jira

Finally, as a software engineer, there are times when you just want to access your database quickly. Whether it’s to test out your code or clean up a collection after a test run, there are times when using a REST API makes more sense.

Using the Data API

The Data API is now easier than ever to use in MongoDB Atlas. With the integration of the Run in Postman button, you can try out the API with a single click. Here’s how:

  1. Log in to your MongoDB Atlas account. If you don’t have one, you can create one for free.
  2. Create a cluster following the steps in the documentation.
  3. From the left navigation bar, select Data API and toggle the feature on your cluster.
  4. Click on the green Test Your API button in the upper right corner. This will open a modal where you’ll see the Run in Postman button.
A screenshot of the Altas UI featuring the Run in Postman button
You can test your API in Postman by using the Run in Postman button from the Atlas UI

This will fork MongoDB’s Data API collection to your own workspace. From there, you will be able to pick the environment created for you.

You can learn more about the Data API and how you can use it with Postman in the MongoDB podcast’s episode featuring Postman Senior Developer Advocate Arlemi Turpault.

How MongoDB Atlas integrated with Postman

The Postman team did a great job at making it easy and intuitive for software vendors to integrate the Run in Postman button with their platform. Adding the button to the application was simply a matter of using the code from the documentation in the Atlas UI.

The boilerplate code consists of a div tag and a script to load up any required dependencies:

The default behavior for the Run in Postman button prompts users to fork a collection. You can also configure different actions, for example, to import the collection.

The fork option lets the user create their fork of the Postman Collection, and they’ll be notified whenever there is a change in the original collection. This can be useful for APIs that might change in the future or to easily notify users of new endpoints added to an API.

On the other hand, the import action will clone the collection into the user’s UI, and they’ll be able to use it directly from the desktop application if they have it installed on their system.

MongoDB decided to use the default behavior, as recommended by Postman. This way, any changes made to the Postman Collection by our team would automatically be made available to all of our users. This fork will open in a new tab, and the user still has access to the Atlas UI to quickly copy and paste the values not pre-populated in the environment.

Speaking of the environment, we wanted to add one with the collection so that Postman users can use the pre-filled fields required for the API. For security purposes, not all fields are pre-populated, though. Currently, only the URL endpoint is filled as part of the environment.

Once the script is loaded, creating the environment is straightforward.

_pm('env.create', 'Data API', {key: value});

With this new environment created, software developers forking the Data API collection have a new “Data API” environment they can use to interact with the API.

Why we like the Run in Postman button: giving developers superpowers

Postman is the best platform for software developers to test their APIs, and the Postman team made it easy to integrate their Run in Postman button as part of our product. We are now offering the best tooling available directly from our application with this new feature, providing software developers with a seamless experience. This gives developers the superpowers needed to build applications without having to do too much grunt work.

You can test the Atlas Data API right now with a free account on MongoDB Atlas, or you can explore the Postman public collection maintained by the MongoDB team directly.

What do you think about this topic? Tell us in a comment below.


Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.