so you may don't even know but people
are making thousands of dollars by
building and selling apis
so in today's video i will introduce a
free way of making online passive income
i'm gonna show you the step-by-step
process of creating a flask api and at
the end of this tutorial you'll be able
to offer different subscription plans on
rapid api website
this website allows you to sell the
access to your api and let people use
the data you are providing
the only prerequisites that you'll need
is basic understanding of python
programming language
although will not write much code and
you'll have the access and permission to
use my code
so you just need to watch this video to
the end and change the code based on
what you need
now let's take a look at what are the
main packages and concepts for this
project as an introduction apis are
application programming interfaces that
enable different technologies to speak
with each other
they can connect things to the internet
for instance
your car or tv can communicate to the
internet using apis
apis use http request methods such as
get post delete and put
so when you enter a website let's say
amazon
amazon gets the data from their servers
using apis and shows them in their
website
for using apis we define different end
points these end points return various
types of data for each specific request
we'll build this project using flask web
framework and use requests library to
set up our api
at the end we'll push the code to heroku
and connect it to rapid api
you may have questions about this
project and i'm here to answer them all
so feel free to ask your questions in
the comments section
in our api users will be able to query
for book details and book reviews they
will make a git request to our api isbn
route and our api will return a json
response containing the book's data
all right now let's sign up for rapid
api
as you can see i'm in the rapid api sign
up page i'm just gonna sign up with
and choose one of my accounts
okay there we have it
okay let's leave it here we can just
create the api right here but
let's first head up to hereku and sign
up for that
in the haircut signup page we need to
fill out the information
so your first name last name your email
address
your company you can just leave it in a
the role that you have it's a
professional developer country of origin
mine is canada and the primary language
is python
and at the end you just need to state
that you're not bought and create
so you
you'll need to check your email and
confirm your email and that's it and you
you can access your account
here you just need to create a new app
and name it for example book
api
and just give it a number so so that it
became available
and choose your region and create your
app
next we should head down to overview tab
click on configure add-ons
and search for haircut
host gr es this one
click on it
and we just need the free plan so
submit the order form
this this is a database that provides 10
000 rows for free and you can just use
this one for now and if you just click
on it you can see the credentials
and you can use this credentials to
connect to your database
in the settings tab
the credentials here are the credentials
that you can use
if you want to see what's inside your
database you can use a website called
admin air
cs5
i'm just going to fill out the
credentials in the
respective fields
and go inside the database and create
the routes and tables for this project
okay i entered my credentials i'm i'm
just gonna log into the
database
and also you can see that there is
nothing in this database so i need to
create a table for this database i'm
gonna
call it boops
for now and
for the first column i just gonna create
the id
type is integer and it's gonna be auto
increment
the second one is
isbn
and this one is a text
the
third one is title
and this one is also a text
the last one is author and this one is
also text
and also i'm gonna just uh
have one for a year and this one is
gonna be an integer
so this is it i'm just gonna save the
database these are my columns
and if you wanted to see what's inside
these columns you just need to click on
books
and you can see there's nothing in it i
should enter the data
and i'm gonna show you how to import the
data in this uh database using python
okay now let's head to pycharm i'm gonna
use pycharm as my editor
so in here we just need to
first install the requirements
and
in this project we are gonna use flask
flash session
psy cop
g2 binary sql alchemy and requests
and the last one is
unicorn this one is for
connecting to the
heroku and using their servers
and flask is just a flat framework
and the request is just for
requesting and getting data from other
apis or
like putting data
this sort of thing sql alchemy is gonna
be used for
uh working with database and
inserting data into my database
and
for running this uh requirements you
just need to
type pip3
and install
our
requirements
dot txt
okay i just missed an e here yeah
this will install the requirements for
us
and you just need to wait until these
are
installed okay uh those are all
installed
so
now i'm just gonna import my data to my
database for that i first need to just
set up my environments
and
just
you don't need to write this code i
provided the github link in the
description you can download the whole
project and just
just run the code
and
see the results in your database
first thing that you should do is to set
your environment
environment variables so
first i will set flask
app
my flask app is gonna be application
dot pi
this is a python file that i have in my
project this one
and i'm gonna use that as my
flask app
next one is set
flask
debug
to one i just want to
see the changes in my
uh project this is why i'm setting the
flash d back to one
the next thing that i need to set is my
database
so i need my database url
this is from my credentials
you just need to copy that credentials
in here and it will
set the database url for us so i just
need to
come here
copy this url
go back to here paste it
and here it is
so
i will explain this code and what's
going on in this
import.pi file
first we need to read
the data that we have from our csv file
it is a csv file containing our
book isbn
book title author and year of
publication
and the skill alchemy as i said is gonna
be used for our database and just
inserting data into our database or
if you wanted to
use it
you can just use it for
reading data from database and selecting
deleting everything
the next thing is just it it's gonna get
our environment variables
here
it will read the database url that we
just entered
for some reason
it needs to be
post
jury
sql in our database as you can see the
first thing that we have in our data
database url is post gres this one is
not supported anymore
you should have a sql at the end
so we just change that here
and then we insert that in our engine
next we need to
create our database and bind it with our
engine
the final part of this code is the main
function you just need to read the
books.csv file
put it inside the variable car reader
and go inside the loop and in that loop
you just need to insert data to our
database and commit changes
and this is it if you will run this code
by python
import
dot pi
you will see that
our
data is gonna be inserted as we can see
here
you can see that it is printing
like here i added added book
title each of these titles are going to
be inserted into our database
and after some time i'm gonna show you
the final result in our database okay
the code finished running
so if we head to the
adminer we can see the data
here that is and you can see we have all
our data imported to our database
okay now let's head back to our
application.pi
file
so in this file we just need to
import some of the packages that we need
one of them is flask render template
json file
session and
packages related to a scale alchemy
we create our app
and with last
then we just read the database url as
before
and the config are the sharepoint as
false
and session type as file system then our
we add the application to our session
next we just need to read the database
url as before and if there is some like
mistakes in our url we just need to add
the sql
at the end
and when the url is changed we are gonna
print uri changed
next we just need to define our route
this is the main cloud we are going to
use
it will render template
index.html file so in our index.html we
have just the file that is
containing
html tags and
the base file so the base file is gonna
use the palma
css package this is just a package for
making the website look nicer
the index.html just is a title and some
text
in it
this is nothing serious these files are
in the templates folder and you can add
them
you
you actually can create a website
and
use flask for
showing uh your detailed
explanation about your api too so
if you want it you can do that too
next we're gonna
define the route for our api
isbn so this means that after a api
anything that you got is an isbn
so
then we are going to pass that to our
function book api function
and select from our book database
those that have the isbn
same as the isbn entered into into our
api
and we committed changes
and if there is nothing in our database
with that isbn we just gonna print an
error
and we say that it's not found
and json if i will turn it into a json
format and print it out to our browser
and at the end if there is a book with
that isbn we will print the details of
that book and
this one should be here
and that's it if we run our application
with flask run
you can see the final result
okay we have our database setup we have
our application setup and if you click
on this
url we will see our
website this is it so this is just the
ui that i created for
our book api you can insert your
explanation about your api everything
that this thing is important and how to
use your api can be here
and it's nothing important i i think
it's just the extra thing that you can
add
and if you go to
api and some
uh
isbn as like this one in our brother we
can't see the detail for that
book
here it is
the year
title and author
of course this is not something that you
can make money off you should be able to
uh think
about an idea for example you can scrap
all the data of climate change or
cryptocurrencies in the news
letters or in the websites that
publish
blogs about
cryptocurrencies or climate change
and gather data inserted into your
database
this method is called web scrapping and
you can use it for
gathering data and
like providing this data to people to
buy
and this one is just for an example this
is a book api also i'm using an
extension google chrome extension called
json viewer it makes the json
format to
look nicer in your browser
and you can just download it from chrome
extensions
now we just need to deploy our api to
hercule and then to
rapid api
for deploying the project to heroku we
need a file called proc file in here we
use conicon to
say that we have this application that
pi file and the name should match
as our app
and heroku should consider
giving us a server in their side so this
is what it does
now we can go to hair group
and in here in the deploy tab we just
need to
use these commands in our terminal and
deploy our project so we use herku login
i'm just gonna copy them
it will
prompt us a login page
you just need to press any key
here it is we need to just log in
it's locked in and we
go back to our eriku
in here we
we should create a git repository so you
should just cd to your project and
write kit in it
okay
and then you need to copy hercule git
remote
a book api to
this is it
so now you just commit your you just add
your
uh files to git
this will take a while so just wait for
it
after adding the files we just need to
copy the other codes
we should commit our changes
we can just call this one
comic one
then we need to copy the last part
and push the code to heroku
okay we just need to wait for this to
finish
okay now we have our project in the
herku
and
when the deployment is finished it will
give us the link
and if we click on it we can see our
project on herku
as you can see the url is
matching
to our
api that we entered in the hair cool
and the last part is to
set up our rapid api
okay now it's time to actually create
our api on rapid api you just need to
give it a name for example book e10
and the description will be like
something like this api will return
details of books based on their isbn
the category will be
media or like data something like that
and we just need to leave it as ui and
add api
okay here we just need to
provide a longer description
and i'm just gonna copy this and you can
just write them something better
in the future
i'm just gonna like write for an
instance
title
author
yeah of
publication
okay i uploaded my youtube channel logo
here
you should provide the url to our
api so i'm just going to copy this
url here
and we just specified the media
and term of use we don't have any terms
of use
here it is we have it now
now we just need to add the base url
here i'm just gonna configure configure
the
default one the default one is uh as
the last one that we have
we entered
here this is the default one
we need to just add
end points
so
for our end points we just need to
create rest endpoint
name it's like something like
uh isbn
the description something like
this will
return
the details
of books
and
for the external link we just leave it
blank
and
for get we
write api slash
something like isbn as it says
here it is and for test values we can
just enter the test uh isbn data entered
here
it will be any stream and
as you can see it will provide us with
some examples
and we
can choose python
and
requests for example as you can see it
will pre print our api and some
isbn number
and at the end we just need to
provide some
body for it like for example you can
just uh
create some responses
and
as
follows for example response 200 will be
something like
the response that we got here
this one actually should be some
explanation about the
response for example
details
of
the book
and we should just save it
as you can see we added isbn endpoint
and it's a get request
so
this is it and we should go to the last
part and make your api public and we
just need to check this one to make
api public
and this is it and we have our api now
we can
view in the hub
it says that create is created by me
and also
it's loading the api playground
all the details that we entered are here
the last thing that we should do and you
can see the like example response
and the last thing that we should do is
the pr plans and pricing
for plans and pricing we can
edit the basic one
for changing the basic one we can
uh select the monthly plan and
for quarter limit we can
like write 500
and
if they go over that 500 per month
request we can charge them more and for
example
0.1
per extra
and this is it we can save this one go
to pro plan
for pro plan we can
add a
basic price for instance ten dollars or
something reasonable
we need to add a
object name
for instance
on
the data
some description and say
and choose all the data you can just
change the monthly plan the quota limit
as
we change for the basic one
and you can save plan of course you
should just
i'm gonna just leave that as unlimited
here it is we have our api set up and
we just need to
market it marketing your api you can use
linkedin or facebook and just tell
people that you created an api and they
can use it
or you can just leave it fee and it will
generate you passive income because
rapid api is a
api marketplace and if people search
something they can find it here
and as you can see our api is complete
and we just get these uh this isbn
number and we will
generate a result based on that this is
it
and they can use any language they want
for their project for example people can
come and
select php
and it will generate them
the php code that is required to use
your api
and
you don't need to do anything anymore it
will just
be
completely automatic and we just created
our first api so congrats
so this is it i hope you enjoyed the
video and please smash the subscribe
button because i will be posting videos
like this and
yeah see you next time
[Music]