How to build API and sell on Rapid API
Asa front-end developer, you have to grasp the knowledge about how to fetch the API. But there is a question coming, where the API comes from? Why I can fetch data with a simple URL link and a private API key for some of them.
Occasionally, I found a video about it. The curiosity leads me to find out further. Here is the link. I am gonna record what I learned.
First, you have to make an app with node.js.
Make sure Node.js is installed on the PC.
In the project, npm install express request request-promise nodemon
In the package.json file, change the scripts for running.
so, you can run the terminal with npm run dev
or yarn dev
to run the live server.
In the index.js file, we begin to build the code.
require express and request.
the port default is 5000
the home page is the sentence: Welcome to...
When the port is 5000, the app listens and runs.
For doing a ScraperAPI, I went to scraper API to register an account, then you can get the API key. the free limit is 5000 credits.
this function is for the apiKey purpose, the user can get their own. But when you are on test mode, you can fill in your API key.
GET DATA from the site.
- Get the product details.
request the data from www.amazon.com
Find any one product on Amazon, you can see the link. Such as https://www.amazon.com/2021-Apple-iPad-Mini-Wi-Fi/dp/B09G91LXFP/ref=sr_1_6?crid=GX5BYWEIU2CM&keywords=apple&qid=1642867703&sprefix=appl%2Caps%2C215&sr=8-6
the link showing the product name and /dp/B09G91LXFP. the serious words and numbers are productID.
Then try it on in your server with http://localhost:5000/products/B09G91LXFP
You can get a JSON file with the product name, price, and other details listed.
btw, by a formatted JSON file. you can get the chrome extension JSON formatted.
2. the same way for getting product reviews
careful for the URL link
3. get product offer
the offer-listing is under the gp located.
If the product has no offer, the attributes are empty
4. get product results
the search is not the productId anymore.
Second, try to deploy on a live server with Heroku.
Go to Heroku and sign up for an account, the free account, you can do 5 projects at most.
create a project, give it a unique name.
at the deploy section, you have several methods to deploy.
Here I use the first one with Heroku CLI, download the Heroku CLI on PC.
If you haven’t already, log in to your Heroku account and follow the prompts to create a new SSH public key.
$ heroku login
Clone the repository
Use Git to clone your source code to your local machine.
$ heroku git:clone -a amazon-scraper-test
$ cd amazon-scraper-test
Deploy your changes
Make some changes to the code you just cloned and deploy them to Heroku using Git.
$ git add .
$ git commit -am "make it better"
$ git push heroku master
Then you can have it on Heroku. you can run on the https://yourprojectname.herokuapp.com/
Third, upload on Rapid API.
Sign up for Rapid API, go to my APIs, add a new API.
set up the name and details.
you can upload the logo image and the terms if you have them. The website link is the link you get from Heroku.
- add a base Url
2.add an endpoint
3.You can also set up Security
4. plan and pricing
The API makes developers’ life easier. It’s a good way to share resources and learn. Peace.