Blog Logo

Earn Money Creating Your Own REST APIs

Earn Money Creating Your Own REST APIs

Everyone likes money, but above all what we like is being able to earn money to have more freedom and dedicate our time to what we really want to do, not what we are forced to do.

Sometimes I rack my brains thinking of different ways to get some extra money so I don’t have to rely exclusively on a conventional 9-5 job. And whenever I ask myself those questions, I realize that I am a programmer and therefore I have it much easier than other people.

Fortunately, programmers get paid quite well unlike other trades that are currently in the market. But no matter how well we get paid, it is not always enough to live the life we really want to live. Even if we have a good salary, we are tied to a conventional job that forces you to get up early, enter in the morning and leave in the afternoon. That is, we are exchanging our time for money. And time, friends, is very important.

As programmers, we have a huge advantage: we can write code once and have people from all over the world use it. And that can give us an economic benefit without having to be present constantly.

One of these ways to get money taking advantage of the fact that we are programmers is creating an API and making people who want to use it have to pay for its use. But how exactly is it done?

In this article we are going to see what an API is, what types of APIs you can create, how to create an API, how to upload it to the cloud, how to monetize it with RapidAPI and various ways to promote it.

That’s right, I’m obsessed with decoupling my income from my time. And I’m pretty sure that by doing things like these I’ll end up achieving it. Mind you, nobody says it’s simple. I’m not going to sell you smoke: I can’t promise you that you’re going to earn a trillion dollars, I would be lying. But I do assure you that this is one of the methods you can take advantage of being programmers, and depending on what you want to do with your API, you won’t have to dedicate too much time.

What is an API?

First of all, in case you entered and don’t know, I’m going to quickly explain what an API is. Although if you are a programmer and don’t know, you have a serious problem.

An API is basically a structured way to communicate with a service without having to access its code directly. Basically they are a set of endpoints that allow you to request data or send data.

There are lots of examples of APIs. Everything right now goes with APIs. To give you an idea, if I want, for example, to make an application that extracts Twitter statistics, I will need to connect to the Twitter API to receive that data. Or if I want to make a Twitter bot, so that it talks to itself and sends messages automatically on Twitter, I will need an API to act as a gateway and allow me to send those messages.

APIs serve for everything, even if you want to implement Google Maps in your application, you need access to the Google Maps API. So, everything goes through APIs. And there, gentlemen, we enter.

What API can I make that gives me money?

At this point, you will ask yourself: and what API can I make that gives me money? Well, you just have to use your head a little and I assure you it is not that complicated.

You don’t need to make a Twitter API, you don’t need to make something colossal and super complicated, unless you want to make it. I’m going to give you some tips on what I think could be good utilities that you could do yourself.

Now scraping data from web pages is very fashionable, and this is super useful. Many people look for this type of services because they are too lazy to make their own APIs to extract data from other websites. And that’s where you can enter.

Without going any further you can make an API that scrapes data from Mercadona, Carrefour, several supermarkets or even all of them. That information is super useful for someone who wants to make a price comparison application or track prices, things like that. And if they don’t want to set up that API they are going to need your services.

I don’t know if there is a Mercadona API, I said it as an example. But it doesn’t matter if it already exists, and that is precisely the important point.

I recommend visiting rapidapi.com, which is the platform we will use to monetize our API. There you can see examples of existing APIs to get inspiration.

And not only to inspire you, but you can also make your own model. If a similar API already exists, nothing happens. You can make it too, but better, different, faster or at a lower price.

Don’t get discouraged if your idea already exists because nothing happens. You can compete in the market. This is not like competing with big brands. This is mostly individuals and surely if something exists, maybe you can improve it or adapt it to a different utility. It doesn’t have to have the same endpoints and you can make a product not better, but different.

The important thing is to do it well and that way you will really compete.

How do I create an API?

Well look, there are many ways to create an API, you don’t have to do it with a specific language or technology, you can do it with many, really, there is a wide range.

I, personally, have chosen Python with FastAPI, but seriously, make the API with the language you feel most comfortable with, because it will be important that you can maintain it yourself and it is your tool with which you are going to make money.

So don’t do it with Python because it’s the fashion or with Java because they told you it’s more robust, no, do it with whatever you want.

Is it better to do it with Python? Well, it depends. For this example I use Python because it is simple to explain and understand, but as I said, everyone is going to do it with the language they want and there are lots of tutorials on the internet on how to make them.

To explain it simply, I’m going to use Python with FastAPI as an example. The basic structure of an API is quite simple: you need to create endpoints that respond to HTTP requests.

In a basic example, you could have a main.py file where you define your data models (for example, an Item type with name, description, price, etc.) and then create endpoints that return that data. In a real case, this data would come from scraping, a database, or any other source you need.

The typical structure includes endpoints like:

  • GET /items to get all items
  • GET /items/{id} to get a specific item by its ID

Inside each endpoint you define the logic you need: searches, filters, data transformations, connections with other APIs, etc. The key is that each endpoint does one specific thing and does it well.

I have uploaded a basic example to GitHub so you have a reference on how to start. You can use it as a base and adapt it to your needs.

Security: an essential layer

One of the most important aspects when creating an API that you are going to monetize is security. If you don’t protect your API, anyone can directly access your server URL and use it without going through RapidAPI, that is, without paying. And that, obviously, we don’t want to happen.

RapidAPI makes this much easier by providing you with a unique secret for your application. This secret acts as an authentication key that you must validate in each request.

The basic implementation consists of:

  1. Save the secret as an environment variable: RapidAPI will give you this secret when you configure your API on their platform. You save it as an environment variable so as not to expose it in the code.

  2. Validate the header in each endpoint: In each endpoint, you verify that the request includes the correct header with the secret. If it doesn’t match, you return a 403 error (Forbidden).

  3. Use decorators or middleware: Depending on the framework you use, you can create a decorator or middleware that automatically validates all requests before they reach your endpoints.

This is the basic security layer. If you want to go further, you can configure your server to only accept requests from RapidAPI IPs (they provide the list of allowed IPs). You can also use tools like Cloudflare to add additional layers of protection.

It is absolutely critical that you implement some type of authentication. If you don’t, your API will be constantly attacked. In my experience with my TikTok download API, even with Cloudflare in front, I receive constant attack attempts looking for vulnerabilities. Without authentication, your API will be abused mercilessly.

About the specific technical implementation, there are lots of tutorials on the internet and you can also use LLMs to help you with the code. The important thing is that you understand the concept: you need to validate that whoever calls your API has permission to do so.

Deploying your API in the cloud

Deploying your API can be done in different ways, especially if it is Python, because it is quite versatile.

You have tools like Render or Railway that have a very friendly interface and help you deploy these APIs. They have official documentation on how to deploy a FastAPI API on their platforms.

The problem is that they are paid. They have a free version but it is limited. And if your API is going to have a lot of traffic, those limitations can be a problem. That’s why I prefer to use my own server.

Having a server can cost from 5 euros a month, which is quite reasonable to support an API. But in my case, I use a free Oracle Cloud server that has 24 GB of RAM and 4 cores. It is not nonsense, it is a pretty good server and totally free.

If you are interested in getting this server, I have a tutorial on the channel where I explain how to do it step by step. You don’t have to do it there, but it is a very valid option if you want to start without investing money.

To deploy the API I use Coolify, which is a visual manager for servers that makes the process much easier. If you don’t have Coolify installed, I also have a complete tutorial on how to install and use it. It can be done without Coolify, sure, but it’s several commands and I prefer to use tools that make my life easier.

Configuring Docker for deployment

To deploy the API we need to dockerize it. This requires two important files: a Dockerfile and a docker-compose.yml.

The Dockerfile contains the commands to build the Docker image with your API. The docker-compose.yml defines the container configuration, including environment variables like the RapidAPI secret.

It is good practice to have all the code on GitHub, so you have better version control and can easily import it into Coolify.

The Dockerfile is pretty standard: you use a Python base image, update system dependencies, copy the requirements.txt file with your API dependencies, install them, expose the port you need (for example, 8000 or 8080) and define the command to start the API with uvicorn.

The docker-compose.yml allows you to define the container configuration: the project folder, ports and environment variables (like the RapidAPI secret). Environment variables are easily passed from Coolify when you configure the deployment.

With these two files you already have everything you need to dockerize your API. It is a simple configuration but enough to start.

Deploying with Coolify

Once you have your code on GitHub and the Docker files configured, deployment with Coolify is quite straightforward.

In Coolify you create a new project, select the option to import from GitHub and choose your repository. You will need to configure:

  • The domain or subdomain: You need a domain for your API to be accessible. If you have your DNS in Cloudflare (or any other provider), you simply create an A record pointing to your server IP. For example, api.yourdomain.com.

  • Environment variables: This is where you pass the RapidAPI secret we mentioned before.

  • Docker configuration: Coolify will automatically detect your docker-compose.yml and use that configuration.

Once deployed, you can verify that everything works by accessing https://your-domain.com/docs (if you use FastAPI, you will have the interactive Swagger documentation available automatically).

With the API running and accessible, you can now connect it with RapidAPI to start monetizing it.

Monetizing your API with RapidAPI

Before continuing I want to clarify that there are many ways to earn money with your API and you don’t necessarily have to do it through RapidAPI, simply this platform helps us do it and offers us its own portal, but you could set it up yourself with your payment system, only it is more expensive. Although you must also take into account that RapidAPI will keep a commission, I warn you so that you take everything into account.

In RapidAPI, inside Studio, you create a new API project. You will need to provide:

  • Name and description: That are clear and explain what your API does
  • Base URL: The URL where your API is deployed
  • Health Endpoint: An endpoint that RapidAPI can use to verify that your API is working
  • Security token: The secret we mentioned before, which RapidAPI will provide you and which you will use to validate requests
  • Endpoints: Define the endpoints you want to expose
  • Pricing: Configure your pricing plans

Pricing configuration is crucial, since what you put will make the difference between a used API or an API that is barely used.

I recommend that you look at what volumes the competition handles, note that many people put a free tier with few requests so that people try their product, and if they really like it and find it useful they pay for a higher tier.

Study the market well and set competitive prices, believe me it will help you attract new people.

Important that you activate payments from the profile section called “Payouts account”, there you can link it with your PayPal and receive payments directly there.

With all this that I have explained you already have the basis to monetize your APIs. But there is one more step that is equally important: promoting it.

How to promote your API

I don’t want to sell you smoke: if you publish your API and don’t advertise anywhere, it will hardly get users. The important thing is to know how to move and advertise your API. I myself have a TikTok download API that I haven’t given any publicity to, so I know what I’m talking about.

Several examples occur to me of how to advertise your API:

Through Reddit, creating a new post or responding to the post of someone who has asked for a functionality similar to the one you have developed.

Creating your own product. For example I have seen many people who create quite useful N8N flows that use their APIs exposed in RapidAPI, so if you want to use that same flow it is free but they use your API. Ideas of that style I think would help a lot to boost your product.

I have also seen people who make N8N scripts where it has a functionality that calls their API, then the script is posted for free, says hey guys I posted this script, you can publish it on LinkedIn, on Reddit wherever you want, but that script needs the use of your API and to go through your API they have to pay and that’s it, as simple as that.

There are a lot of super ingenious ways, I’m sure you will come up with some.

Conclusion

With all this that I have explained you can start monetizing your APIs. It is a process that requires work, but it is totally feasible and can become an interesting source of passive income.

The most important thing is to start with something simple, make sure it works well, and then improve and promote it. Don’t expect to earn millions from day one, but if you do things right and move intelligently, you can get some extra income that helps you have more financial freedom.

If you have doubts about any step or want to share your experiences creating APIs, leave me a comment. I would also love to know what type of API you are thinking of creating or if you already have one running.

See you in the next article!


What do you think?

Leave your opinion, question or suggestion. Comments are synced with GitHub Discussions .

Back to blog