Detailed Notes
Building an API is more than just simple calls. We provide an example of Python Flask and a DELETE request as part of our series of tutorials around a URL shortener.
You can find out more through our online classes at https://school.develpreneur.com and register for free. Registration will add you to our email list and you will periodically receive coupons for courses as well as notifications of the latest releases.
Transcript Text
foreign [Music] well hello and welcome back we have moved our way through our apis and one of the things I want to do is handle a couple of the sort of round out a couple of these particularly the delete call so we prior to this we had just something just kicked out a little you know result text so what we're going to do is we actually want to go in and when we get a delete request then we want to actually delete that record so if we go into our test what we're going to end up doing I'm going to do almost the exact same thing and so here where it's doing a get we're going to do combo here because we're going to do is we're going to do a post and this is going to be payload where URL equals uh we're just going to call it my test url.com slash blah and that's going to be our payload what it is like pretty it up a little bit here oh like that I cannot be the side of my time oh URL equals that believe is how we want it to go let's start with here let's actually go out here and so if we run let's go ahead and add our little terminal if we go in here and we run our API call so we're going to run this so now we're running our API and so we can come in and look here this is on 4001 let's see this is the get so let's say do we have uh method not alone uh let's see that is a oops it says Purge we don't want Purge we want to get okay so we get a status here and if we look here uh so what we want is oh so this is going to be so we have to tweak stuff a little bit because there's some space here so we're going to do our base is actually what did I call that localhost and and do that it's a local host this is not gonna get anything but if I post let's go look at this if I'm going to post something uh URL we're going to send that uh 5001. so let's create a record Okay so we've got this record that it sent and then what we want to do on a get is take that same one which I think we can do here just leave that there uh do I need I probably don't need that I can do it like this so he's going to get back my ID okay so I'm good here so let's do a second one and let's do um bad URL so it brings back so that's gonna be number seven if we do number seven there we go so now what we want to do is we're going to do it's very similar to the get step four this one's going to be a delete and so we want to do here is and we're going to see what we're going to take from the delete so the delete where'd it go uh leads over here on our API and we're coming and we're going to get our URL and so we can do is we're going to say here this is actually going to be uh we're going to get URL so navigate url url let's just do it's going to be a request Arc here so instead of this being a query program um oh no that's right so it doesn't need to be a body it's just going to be a query parameter and we're going to do it here we're going to delete now if we do it right now it's going to tell us that there's an error because it's going to blow up it doesn't like that because oh because I started to code this so now we're going to go to shorty delete so instead of navigate uh instead of is that what we wanted that's new URL so this is the one we want so we'll do it sort of like this so now what we're going to do is we're going to do a delete and where you don't need to do that we do want to get the index and then what we're going to do is we're going to come up here where did we do that oh so we're just going to do this basically the same because this one actually does a oh let's just do this let's go in here and let's do a delete link and we either get an error or we get a result and this is going to be in uh my DB which is this guy so here instead of is that where it's at uh get next number retrieve length there we go so this is going to be delete link and we're going to come in and this will be actually pretty straightforward because we're going to do we're going to do a delete from links where code equals that he's going to do an execute he is going to need to do a um soft uh oh he does we probably do want to do a commit and then let's just do uh so equals after deleted uh new ID we don't need that we don't need to return new ID because we're not using it at all cursor close uh uh oh yeah I think we can do that and we're going to return results so let's see what happens do that and then we go foreground and kill it so now we're going to run it again okay and actually we'll just leave it there we don't have to background it here so now what we're going to do is let's see let's just do that we'll go right in and we're going to delete it and let's see what happens gives us record deleted success so if we come back over to our uh let's save this first is going to be a shorty delete and put it there there we go so we've got short delete if we go to shorty get now it's not going to find it because we have deleted the record so we have added the ability to do a delete now without doing a whole lot of extra work and this again is where you go into where the API is it's one of the nice things about it is when you use the the request methods you can basically have like here we have really just one endpoint and from there we're going to be able to post so we can insert something we're going to do a get and we're going to do a delete we don't really have when you look at some of the others we don't have some of these others that don't make as much sense so now we've got a very simple way to come in and provide for a deletion of it so that's a really uh I know it's a little bit of a quick and dirty one but I did want to take a look at that show you how to implement a delete within flask and we're going to come back and sort of wrap this thing up start looking at how we can deploy this some of the little tweaks and things like that we need to do part of the configuration because we're going to use this on a or actually deploy this to something that uses an Apache server if you use something else you know as a front end then it'll vary a little bit but at least we'll give you those instructions that being said hope you go out there and have yourself a great day and we will talk to you next time hello this is Rob with developmentor also known as building better developers wanted to announce that we have school.developmentor.com feel free to check it out if you like any of this information any of the content that we've sent and you would like to see more you can come out you can roll for free we have free courses we've got places for you to get better at just learning a technology our how to's you can work on your business skills we can help you with becoming a better developer as encoding and things like that a lot of the stuff you've seen on YouTube we also have out at school.developmentor we just have it a little more of a educational format and a way for you to track your progress as you move forward becoming a better developer foreign
Transcript Segments
foreign
[Music]
well hello and welcome back we have
moved our way through our apis and one
of the things I want to do is handle a
couple of the sort of round out a couple
of these particularly the delete call so
we prior to this we had just something
just kicked out a little you know result
text so what we're going to do is we
actually want to go in and when we get a
delete request
then we want to actually delete that
record so if we go into our test what
we're going to end up doing I'm going to
do almost the exact same thing
and so here where it's doing a get
we're going to do
combo here because we're going to do is
we're going to do a post
and this is going to be
payload where URL equals uh we're just
going to call it my test
url.com slash blah
and that's going to be our payload
what it is like pretty it up a little
bit here
oh like that
I cannot be the side of my time oh
URL equals that
believe is how we want it to go
let's start with here let's actually go
out here and so if we run
let's go ahead and add our little
terminal
if we go in here
and we run our
API call
so we're going to run this so now we're
running our
API
and so we can come in and look here this
is on 4001 let's see this is the get so
let's say do we have
uh method not alone
uh let's see
that is a oops it says Purge we don't
want Purge we want to get
okay so we get a status here
and if we look here uh so what we want
is oh
so this is going to be so we have to
tweak stuff a little bit because there's
some space here so we're going to do our
base
is actually
what did I call that localhost
and
and do that
it's a local host
this
is not gonna get anything but if I post
let's go look at this if I'm going to
post something
uh URL we're going to send that
uh 5001.
so let's create a record
Okay so we've got this record that it
sent
and then what we want to do on a get is
take that same one
which I think we can do here
just leave that there
uh
do I need I probably don't need that
I can do it like this
so he's going to get back my ID okay so
I'm good here so let's do a second one
and let's do
um
bad URL
so it brings back so that's gonna be
number seven if we do number seven
there we go so now what we want to do
is we're going to do it's very similar
to the get
step four
this one's going to be a delete
and so we want to do here
is and we're going to see what we're
going to take from the delete so the
delete
where'd it go uh leads over here on our
API
and we're coming and we're going to get
our URL and so we can do is we're going
to say here this is actually going to be
uh we're going to get URL so navigate
url url let's just do it's going to be a
request Arc here so instead of this
being a query program
um oh no that's right
so it doesn't need to be a body it's
just going to be a query parameter
and we're going to do it here we're
going to delete now if we do it right
now it's going to tell us that there's
an error because it's going to blow up
it doesn't like that
because oh because I started to code
this so now we're going to go to shorty
delete
so instead of navigate uh instead of is
that what we wanted
that's new URL so this is the one we
want so we'll do it sort of like this
so now what we're going to do is we're
going to do a delete
and where you don't need to do that
we do want to get the index
and then what we're going to do is we're
going to come up here where did we do
that oh so we're just going to do
this basically the same
because this one actually does a
oh let's just do this
let's go in here and let's do a delete
link
and we either get an error or we get a
result
and this is going to be in uh my DB
which is
this guy
so here instead of is that where it's at
uh get next number retrieve length there
we go
so this is going to be delete link
and we're going to come in and this will
be actually pretty straightforward
because we're going to do
we're going to do a delete from
links
where code equals that
he's going to do an execute
he is going to need to do
a um
soft uh oh he does we probably do want
to do a commit
and then
let's just do uh
so equals
after deleted
uh new ID we don't need that we don't
need to return new ID because we're not
using it at all cursor close
uh
uh oh yeah I think we can do that and
we're going to return results so let's
see what happens
do that and then we go foreground
and kill it so now we're going to run it
again
okay and actually we'll just leave it
there we don't have to background it
here
so now what we're going to do is let's
see let's just do that we'll go right in
and we're going to delete it and let's
see what happens
gives us record deleted success so if we
come back over to our uh let's save this
first
is going to be a shorty delete
and
put it there
there we go so we've got short delete if
we go to shorty get
now it's not going to find it because we
have deleted the record so we have added
the ability to do a delete now without
doing a whole lot of extra work and this
again is where you go into where the API
is it's one of the nice things about it
is when you use the the request methods
you can basically have like here we have
really just one endpoint and from there
we're going to be able to post so we can
insert something we're going to do a get
and we're going to do a delete we don't
really have when you look at some of the
others we don't have some of these
others that don't make as much sense
so now we've got a very simple way to
come in and provide for a deletion of it
so that's a really uh I know it's a
little bit of a quick and dirty one
but I did want to take a look at that
show you how to implement a delete
within flask and we're going to come
back and sort of wrap this thing up
start looking at how we can deploy this
some of the little tweaks and things
like that we need to do part of the
configuration because we're going to use
this on a or actually deploy this to
something that uses an Apache server if
you use something else you know as a
front end then it'll vary a little bit
but at least we'll give you those
instructions
that being said hope you go out there
and have yourself a great day and we
will talk to you next time
hello this is Rob with developmentor
also known as building better developers
wanted to announce that we have
school.developmentor.com feel free to
check it out if you like any of this
information any of the content that
we've sent and you would like to see
more you can come out you can roll for
free we have free courses we've got
places for you to get better at just
learning a technology our how to's you
can work on your business skills we can
help you with becoming a better
developer as encoding and things like
that a lot of the stuff you've seen on
YouTube we also have out at
school.developmentor we just have it a
little more of a educational format and
a way for you to track your progress as
you move forward becoming a better
developer
foreign