Earn a Passive Income by Monetizing APIs as a Developer

•

Mon Aug 08 2022

•

16 min read

Are you aware that you can generate income by selling your APIs? Building and selling APIs is an excellent method to establish a new income stream.

Hence, you will learn how to do it in this guide! You will first build an API from scratch before selling it on RapidAPI Hub.

What's an API?

To get things going, let's review what an API is. Application Programming Interface, or API, is a term that refers to a method of communication between two computer applications.

Simply said, it's a piece of software that provides its services to other programs through a pre-defined set of functions. The functions describe how the API can be used, so the other programs don't need to be aware of how the API is implemented. There are four different sorts of requests that you can use to interact with APIs and perform CRUD operations:

  • GET requests - Get all the information
  • POST requests - Create new data
  • PUT requests - Update existing data
  • DELETE requests - Delete data

The API exposes various endpoints, which are URLs that can be used to make any of the four requests.

You probably interact with an API whenever you view a webpage on the internet. For instance, when you browse a social media platform's newsfeed, you send a GET request to the platform's API to retrieve the posts made by other users. Alternatively, you engage with an API when using your weather or email app on your phone.

Real-World Example

Let's consider an analogy from the real world using a flower shop as an illustration.

You visit the florist to purchase flowers. You walk into the store and request a customized bouquet from the florist. The florist lists all the flowers and decorations you can use. After selecting the decor and flowers, you place an order. When your desired custom bouquet is ready, the florist will deliver it to you. You leave the shop after purchasing the bouquet.

Hence, you (client) made a request to the florist (API) with custom data. The florist went to the flower shop atelier (server/database) and brought your bouquet back (API response).

Why do we need API?

The use of APIs accelerates both the development process and time. Since users may employ ready-made solutions, it also helps to make the developer’s jobs simpler.

It is unnecessary to create something from scratch and waste time on its development that already exists. Take Google Maps, for instance, which developers can integrate into programs and websites. You can use the map given by Google rather than create one each time you require it. Do you realize how much time and money you save doing it this way?

Additionally, it makes it possible to monetize your work. You can build an API and then sell it. For example, the first 1000 requests made each month might be free. However, for each additional request after that, you can charge something like $0.001.

Therefore, using APIs allows you to save time, money, and resources while also allowing you to monetize your work!

Method to sell API

Since RapidAPI Hub is the biggest online hub for APIs, we'll leverage it to make money from our API. The unique feature of RapidAPI Hub is that developers can charge other developers who want to use their APIs . As a result, you may use your APIs to generate income or even make passive income out of them.

Additionally, their platform enables developers to find and use already-existing APIs.

How does it work?

The RapidAPI Hub allows you to search for and use APIs in all categories. For instance, they include APIs for translation, flight information, text-to-speech, and more. Thus, you can find any API that your program requires.

Furthermore, you can use numerous APIs without worrying about utilizing various SDKs and API Keys. With RapidAPI, you can access many APIs from a single SDK, API Key, and dashboard.

However, there's more! You can use this platform to add your APIs and charge different prices for access to them. You won't need to put in any extra effort to market your API. Simply submit your API, choose the tiers, and let developers access it.

In the figure below, you may see an illustration of Weather API. There are four plans available, each with a different cost for this API. Additionally, you can view any additional fees for requests or uploads.

The users can select the plan that best suits their demands and begin utilizing the API. You may turn your APIs into a passive source of income in this manner.

Anyone can sell their APIs, which is the best feature of RapidAPI. You do not need to be a large firm, a well-known developer, or any sort. It is achievable for everyone. Therefore let's see how one can sell their API.

Build and deploy the API

You will use Node.js and Express to create a very basic application in this guide. Because this article aims to demonstrate how you might monetize your API, you will build a dummy API with just one endpoint.

In this example, you will create an application skeleton using the Express application generator. Run the following command in your terminal to start the generator:

sh
npx express-generator rapidapi-example

The application only exposes one endpoint /user, which provides a list of persons with fictitious information. Therefore, before making their application is public, developers can test them using fictitious data using this simple API.

Let's begin by making changes to the skeleton application.

Open the rapidapi-example project. After it has opened, navigate to the views folder and double-click index.jade. Replace the following code with the content:

jade
extends layout
block content
h1= title
p Welcome to #{title}
p See the available list of
a(href='/users') users

The next step is to make a folder in the root directory called data. The JavaScript file, user.js, containing the fake users will be placed in this folder. Then, in the users.js file, paste the following code:

js
const users =
[
{
"email": "melissa.fleming@example.com",
"phone_number": "0740-304-475",
"location": {
"street": "3655 manchester road",
"city": "winchester",
"state": "berkshire",
"postcode": "YB2 8EJ"
},
"first_name": "melissa",
"last_name": "fleming"
},
{
"email": "christoffer.christiansen@example.com",
"phone_number": "05761325",
"location": {
"street": "3391 pilevangen",
"city": "overby lyng",
"state": "danmark",
"postcode": 88520
},
"first_name": "christoffer",
"last_name": "christiansen"
}
]
module.exports = users;

We have created an array of people and then exported it from the file. This is executed so that you can import the data into your API.

Let's now import the data into the API. To begin, navigate to the routes folder and open the file users.js. Then, under the var router line, add the following line to import the array of people:

js
var users = require('../data/users');

After that, replace the line res.send('respond with a resource'); with the following line:

js
res.json(users);

The complete code inside user.js route file looks like this:

js
var express = require('express');
var router = express.Router();
var users = require('../data/users');
/* GET users listing. */
router.get('/', function(req, res, next) {
res.json({ users });
});
module.exports = router;

The users can now access the endpoint /users and receive an array of people in JSON format.

To start and test the application, type npm start in the terminal from the project's root directory. Then, once the application has started, navigate to http://localhost:3000/users to test it. You will see a response like below:

json
[
{
"email": "melissa.fleming@example.com",
"phone_number": "0740-304-475",
"location": {
"street": "3655 manchester road",
"city": "winchester",
"state": "berkshire",
"postcode": "YB2 8EJ"
},
"first_name": "melissa",
"last_name": "fleming"
},
{
"email": "christoffer.christiansen@example.com",
"phone_number": "05761325",
"location": {
"street": "3391 pilevangen",
"city": "overby lyng",
"state": "danmark",
"postcode": 88520
},
"first_name": "christoffer",
"last_name": "christiansen"
}
]

As you can see, the API only has one endpoint that returns an array of people with fictitious information. Therefore, before publishing the API on RapidAPI, it must be deployed on a hosting service.

Deploy the API

There are various platforms where Node.js apps can be deployed, but in this guide, you'll learn how to deploy them on Heroku.

A high-level overview of deploying to Heroku is provided in the guide. I advise consulting the official documentation if you want a comprehensive understanding.

Let's fast deploy the newly created application, shall we? To begin, log into Heroku and navigate to the dashboard. Click the "New" button on the dashboard and select "Create new app."

The next step is to select the region and name of your application. You can use the specifics shown in the figure below or create your own. Click the "Create app" button, as shown in the below figure, after you have finished filling out the details.

When you click the "Create app" button, you are taken to a new page with deployment information. You can use the Heroku CLI or GitHub to deploy your application. Select the method that best meets your requirements.

Nevertheless, you will learn how to use GitHub to deploy to Heroku in this training session. Choose the "GitHub" deployment method on the "deploy" page. Then, look for the repository name and click the "Connect" button when you find it.

It is necessary to select the buildpack for the API before moving on and deploying the application. When Heroku deploys your application, it executes a buildpack script. It's employed to configure your app environment and install the dependencies needed by the application. Installing the Node.js build pack is required because the API was created using the Node.js framework.

The "Buildpacks" area can be found by scrolling down the options page, as seen in the figure below.

The figure below depicts what you should see as you scroll down the page. As shown in the figure, click the "Add buildpack" button.

When you click the "Add buildpack" button, a new popup opens in which you can select nodejs - see figure below for more information. Click on it, then choose "Save changes."

You can now deploy the application to Heroku. First, return to the "deploy" section. If you can't find it, it is the third option in the Buildpacks image.

Once there, scroll to the bottom of the page to find the section titled "Manual deploy" . To deploy your application, you should now see a button that says "Deploy Branch".

The deployment is triggered by clicking the button, which should take a few seconds or minutes. The figure below shows a success message after the application has been deployed.

By clicking the "View" button, you can open the API in your browser!

Finally, you are ready to publish and sell your API on the RapidAPI platform.

Setup API on RapidAPI

In this section, you will learn how to set up a RapidAPI account, upload the API to the platform, configure the pricing tiers, make the API available to the public, and wait for passive income. So, let us begin with the first step, creating a RapidAPI account. To get started, go to the RapidAPI Hub and Sign up using your preferred method.

Following the instructions and when you are done, you should see the RapidAPI homepage, as shown in the figure below; once you have successfully signed up.

You should see an option called My APIs on the homepage (highlighted in the figure above). When you click on it, you'll be taken to a new page where you can enter your API.

You should now be on the same page as the figure below.

When you arrive at this screen, select the Add New API button (highlighted in the figure above). The following action is to enter your API's information:

  • API Name - give your API a name.
  • Short Description - describe what your API does so that others understand its purpose.
  • Category - Choose an API category.
  • Specifying the API - You can choose five options for setting the API. However, please go with the UI in this guide.

After entering all of the information, click the Add API button. As shown in the figure below, clicking the button takes you to the API dashboard.

Click on the second step, indicated in the above figure, to continue.

Adding base URL

The next step involves entering the API's base URL. You can find the base URL for the API used in this guide here

You also need to include the base URL because there will be several endpoints. After that, you must configure each endpoint separately in RapidAPI. For example, this API's only endpoint is this.

The base URL can now be added by selecting the Configure button as indicated in the following figure.

When you click the button, a new pop-up appears in which you can enter the URL. Fill it out and then save it.

Configure the REST endpoint

After you've established the base URL, you must configure each endpoint individually. Select the Endpoints tab.

You have the option of adding a GraphQL endpoint or a REST endpoint on the new page. Click the Create REST Endpoint option since we already have a REST API.

The next step is to set your endpoint's name, description, and HTTP method.

The information for the /users endpoint is shown in the following figure. Keep in mind that you only need to enter the endpoint /users rather than the entire URL. The base URL was previously configured, which is why this works.

Now that your endpoint is ready, you can test it. By selecting any of the save buttons in the below figure, you can save the endpoint.

The Save To Test Endpoint button becomes Test Endpoint once the endpoint has been saved. You can click on it to see if the endpoint delivers the right data. A successful endpoint test can be seen in the figure below; it returned an array of users.

You can decide from here what sample response the API's page should show. This example response aims to assist developers in comprehending what kind of response they should get for an endpoint.

Click the Create example from response button to produce an example response. You only need to do it.

Now that the endpoint has been saved, you may go to the step of setting the pricing tiers. The subsequent stage will include the monetization component.

Plan & Pricing API

Click on the Plans & Pricing option, as seen in the figure below, to do that.

Check out the official RapidAPI guide for comprehensive details on pricing plans. It shows you more complex alternatives like private subscription plans, rate limiting, and custom quotas.

The number of user requests determines the API pricing in this guide. The figure below displays the RapidAPI pricing page. Your API can now be monetized.

Let's begin with the "BASIC" plan, the free option. Click the "Edit" button to configure the tier. When you click the edit button, a new page appears. You can configure your pricing tier on this page as follows:

  • Object Name - This is where you specify how much you want to charge the users. For example, with this API, you can charge people based on how many requests they make.
  • Quota Type - The type of quota for users specifies how many requests are free each day/month.
  • Quota Limit - You specify how many requests are free with a quota limit. Users in this example can make 500 free requests per day.
  • Limit Type - There are two types of limits here: hard and soft. A hard limit means users cannot make additional requests after exceeding their quota limit. On the other hand, a soft limit means that users must pay a fee if they exceed their quota limit.

In this case, the free API tier will have 500 free requests per day. Users will be unable to make further requests if their quota is exceeded. The figure below shows the pricing tier configuration.

Let's similarly introduce some paid programs. After all, our primary goal is to make money, isn't it? As depicted in the figure below, select the "Add Plan" button from the "pro" section.

The usual information regarding the tier can be added on the newly opened page. Since you want to charge based on the number of user requests, choose "Requests" for the object name.

After that, enter the following information:

  • Quota Type - Select the monthly quota type.
  • Quota Limit - enter 10000 to allow people to make 10000 free monthly requests.
  • Limit Type - Set a soft limit for this endpoint and charge $0.01 for any additional requests.

You have now completed the pro plan as well. Before it takes effect, scroll down to the bottom of the page and save it.

After saving the plan, you can return to the pricing dashboard and view the configured tiers. ​​

You can also click the "Preview" button in the image above to see the plans in greater detail. As a reference, refer to the image below.

The Ultra and Mega tier configurations are similar to the two plans you already put up.

In the next step, the API must be made public so that other developers can utilize it.

Publish the API

You must make your API public before anyone can use it and pay for it. As shown in the figure below, navigate to the Global Settings.

Once there, change the API visibility to "public." Click on the switch indicated in the figure above to accomplish that. When you click the switch, a new pop-up alerts you that you are about to make your API public. Finally, click the "Make API public" button, and you're done!

Your API should now be visible in the RapidAPI Hub. That means the API is open to the public and can be used by other developers in their applications. The following illustrates the example API from this guide on the RapidAPI hub.

Wrap up

Congratulation on selling your first API! What you learned in this article is:

  • What is an API?
  • How to create and deploy a basic API?
  • How to monetize access to it on the RapidAPI hub?

As you can see, selling your APIs has a lot of potentials. Once you build the API, you can sell it multiple times.