📺 Develpreneur YouTube Episode

Video + transcript

Making use of POST,GET,DELETE and Other API Calls.

2023-08-08 •Youtube

Detailed Notes

Building an API is more than just simple calls. Those are often a GET request and there are many others available. This video looks into them and adding those into an API we created with Python and Flask.

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 are
cruising along in our little shortener
application doing a series of questions
and answers basically to get you through
some key things so basically we're going
to do here is we're going to talk a
little bit about we've got ourselves so
we've got an API that we're calling from
python
we are now going to talk a little bit
about get and post and deletes and
request types A little bit really more
uh the getting the posts and just sort
of how these things work and what you
should be doing to actually craft like a
decent API call because what we've got
right here
just kicks out if you see it when we do
calls it just kicks out some nice big
texty thing which is really not
generally useful I mean you can see it
here is it's just here's your text what
we really want is something that is more
workable because our raw notice is the
same as our pretty
and we're jasonifying stuff
when we don't really have a need to so
what you normally want to do
is you're going to have something in
your message that you're going to send
back so we're going to change up our API
this time
and what we're going to do
is we're going to actually start working
on this a bit so instead of
uh let's see do I want to call that
I'm trying to think if I want to go
ahead let's go ahead
and we'll come back to this another time
because I know I was going to hook the
whole thing up but
uh I could probably do that pretty quick
okay
so let's see
um
yeah I can probably do this so let's try
this
so here's what we're going to do
so we've got a little database
set up
we got a couple calls so we're going to
go to shorty
and over here
we're going to import
or actually how does it look uh it is uh
from DB create
whoops
import
my database I think that's what I want
to do
whoop
my database there we go
so now what we're going to do here is we
don't have to worry about our counter
anymore
but we do want to do is
we're going to actually let's do in a
knit
and take all of that
like this
and so let's see we're gonna set up our
database we don't need to create one
there's a database name we're going to
pull oop import
uh
let's do
this we're going to change this around a
little bit
so we're going to come in here
and we're going to do this
take that I'm going to come over here
so first thing we want to do is we're
going to set up we're doing a little bit
of changes here is we're going to come
in and we're going to set up our
database
we're going to get here
we're gonna get his name I think that's
all we need here
we don't need to create a table uh we
don't need rows
oh we do want to steal one of those
calls insert record links okay so those
are the ones we're going to need so we
need
searches and then we've got a connection
that we don't need to worry about right
now
let's do this
so we're going to use its Constructor
which means we create this shortener
it's going to go through these things we
don't need it to go through these
so let's do that
and now what we want to do is so
navigate
is going to be
just going to do a retrieve link
based on the number
so here
he's going to do
uh let's do my DB
uh let's do this
and I'm going to do my DB connect which
is a
self.idb Connect
and then this is going to be
self.idb dot retrieve link based on the
idx
that
and then we're gonna do we're gonna do
message
well we're gonna do this we'll do that
afterwards so we're gonna do uh let's
see
what's that
we're gonna return
the message but the message is going to
be
and it's going to be status
is status
and
data
is
whoops
pan data
is result
the result there we go status
we're going to do this we're going to
try that
we're going to do this sort of simplify
but and I will walk through this in just
a second except if I can spell it right
and then here
status equals error
their status
SQL status there we go real life results
you probably don't like that
a variable annotation cannot be combined
with Tuple unpacking okay I'm not sure
what that means we're gonna find out in
a second
oh
it probably needs to be this maybe
that's what it likes
okay let's try that so retiring light
retrieval ain't uh yeah okay
so that gives us our Link in the
database
let's see is it going to complain uh
probably
yeah invalid status so we need this to
be oh
because I did that wrong
there we go
uh and so let me go ahead and get this
one done while I'm at it
we're gonna do basically the same thing
so here when we retrieve New York URL
um
our return value so we need to insert a
record link
easy because that's going to be
Health Dot
and then return value
let's say that well let's just do this
it's going to look about the same
let's take that we're going to look
about the same we don't need to close
or return the message
what we're going to try is this
and he's instead going to be
uh
oh here it's looking for a code that's
right so before we're going to give it a
code
so let's go look back here at
dbcreates when it does
or did we do that
create database create table list tables
list rows insert record links here we go
so we were going to give it a number
and let's do
let's do this
we're going to actually get a little bit
funky here so
we're gonna get uh
let's just do this uh we're gonna we're
gonna cheat for now
uh no we're not okay I was going to but
let's we'll come back to this so let's
do uh get next number
and this one's gonna be really simple
because all we're going to do is we're
gonna let's see here here
and we're going to do select Max ID
plus one
from links
and then
this
and let's see result oops
so here we're going to do we can do
because before we did a fetch all we saw
this
here we're going to do effects one so we
don't need to commit
so we're going to do row equals fetch
one
and then
let's see we're going to do ID equals oh
let's do yeah we'll do uh we'll call it
result
so it equals zero here
the result equals negative one
we're gonna print that we're going to
return the result
and this is going to be result
because if we fetch one and it's going
to be zero because we want the first row
uh probably is going to get overwritten
so we can get away with it but we're
gonna let that go anyways okay so that's
gonna be getting X number so when we go
to shorty uh here we're gonna set our
counter so we're gonna do uh we're just
gonna call it
style equals
self Dot mydb
dot get next number
and then here
the return value is just simply going to
be the base
Plus
that
but then we need to save it
uh which I think we're gonna be okay
so that's our return value and so here
we need to take oh this actually
simplifies because now this is going to
be the return value which is the um
the URL the short URL and then the next
thing is going to be the next vowel
because that's what our code is
and then a one because oh because that
was our user so I have to worry about it
and then we have a result okay boom so
now we have Rewritten these things to be
something a little more useful
should run okay so let's go look at
these real quick so if we go
and do a post
of this
oh and shorty
status equals error oh here we go I
forgot to put that there oh which we
also forgot
uh uh here no
here
we want this to be
oh shoot
shorty doesn't really need to do this
because he's
we really want him to be on the API okay
my mistake uh but let's do that anyways
so what we're going to do now is we're
going to pass those through so now
uh this is the so retrieve new new URL
is the result
and then here result
and then here we're just going to dump
the results so now normally we're going
to do this somewhere else but we'll do
these here because that'll just allow us
to get that done
so now if we run this
and we come here and run our post first
then okay data is three oops we did not
want that to be three we wanted our AP
um
when we add a link
uh let's see
insert record link which means over at
Shorty we didn't want it to be the
return value oh yeah
self.base
plus next vowel
oh data is oops my bad
that needs to be return value
because
yes that's going to be successful
insert record links doesn't give
anything oh because that's the new
and we're going to call we'll do this
um
uh let's call that new ID
and that'll be result
otherwise result is zero
let's do that for fun
okay so that is shorty let's get him
here
if we do that
let's get rid of that so now if we run
it
uh so that was three this is probably
gonna be something else okay so four so
now if we take that
and see that's like the pretty version
Raw it's actually about the same
but now we're getting something that we
can actually work with we can do
something with this on the other side of
it
so shorty uh get
and so if I do
four
then he's going to send that back and so
now in my
app
my caller I can actually do something
with this so now my response I'm going
to get something and I'm going to get my
response dot text
and let's go look at the same thing uh
so let's see
so what you already wish to use let's
use this big one
and so now
uh
[Music]
in that literal for INT so what do we do
here
oh
Oops I did that reverse order
so I want this to be this guy
wait right yeah
okay
and so now I can see that I've got data
and
let's see which short URL do you want to
shorten if I take this big one
I've got that
but now I can take the same thing
and let's go change it now so that when
I do
caller
let's see what he wants to do instead
because he's going to do response.text
and he's going to be so the shortened
URL is actually
uh uh the data
so let's see how that works
let's see if we do that now
we do that for short
uh is it not printing out what I wanted
it to
oh yes
that's the problem
not worry about shortening one
and let's see which I already wish to
use
oh so this is because of the way it's
set up so data is what was Data data was
two I think
data is one okay
so it's this just because of what we're
doing so if we do it this way
and we do it this way let's see what
that looks like
so now if we do it
it gives us an empty oh we want
zero let's try that
whoop
oh
let's do this
super spots
data
uh response object is not subscriptable
so we did not do what we wanted to with
this
so let's take a look here so we got that
that's our payload should be that
um
our API is going to send back
that so our call
is that
uh let's see what did we miss here
what was it complaining about it said it
didn't like
response object is not subscriptable so
let's go look at response real quick uh
let's do that
oh
we need to do
uh
where is it
response.data let's go see
let's go look at him again
so that's response is 200.
so if we go look here
I wonder if that is the wrong
brackets that I wanted to use
huh I think so
okay my mistake I was doing a dump to a
string I need to do a jersonify so now I
see something makes a little better
sense and then
uh Where'd I go over here
so now if I do oops I don't want shorty
I want the collar
uh so if he does response
uh well let's look at that first if I
look at that
uh if I shorten
[Music]
okay there's my response
how to response dot data I think
make sure I get this right
um
whoops
uh it doesn't have that so if I do
let's try a response well let's do
next
to that
oh dang it keep hitting the wrong key
uh okay so there's the data and if I do
response text
data
is that going to give me I think that's
going to give me what I want
ah
there we go
uh nope it must be an integer okay
so it's not getting that back out one
second
okay we have to actually do this is
where we want
um
let's see our cell equal Json dot loads
uh oh am I in the right place
that's not really where let's sit this
way I want it here in the API because I
already have it
uh so I'm gonna jsonify the result
oh and then the caller is going to need
that so he's going to need an import
Json
and then he's gonna need from the
response
he's going to do there's no equals
Json dot okay so that loads
the response dot text
and then I can do the result
now I can do the result I'm going to
call that data
look at that
and I think we're going to see here
there we go and so now we're actually
pulling this so we're putting a complex
thing together that's we can check for
like so here we can say
um
if oops I don't want to put it there yet
so I want to come back here and we could
say if
results
uh what did we call that
we called it
here
status
usually we're going to do this from the
API we did it's a little different but
if we take result status
equals
let's say not equal to
success
then
return
status
there we go otherwise you're going to
return the result
so now we're going to get something like
this so if we go here
and we give it something bogus
then it should oh it's going to blow up
uh because we didn't put a try here wait
uh
let's do this
let's just move him up
uh who's that that is shorty so oops
we're going to restart this
start our API now if we do the call
and give it something useless
let's see
oh results
very good result equals negative one we
got to set that up too
so now
let's try that one more time
and let's just give it something that's
bogus
so now it's going to tell us an error so
there you go so now we've actually added
a little bit error checking to our API
which is something you definitely want
to do
final thing is I did want to mention
there's a difference between you have
gits and posts and deletes and updates
and things like that typically as we're
seeing here is use a get to actually get
a value
from it's sort of like a list kind of
thing post is usually going to be an
update which is what we're doing here so
when we're inserting our record we're
going to do retrieve new URL
otherwise if it's a get
which really should be
uh I'll have
to get
then well we're going to do that
what we could do is we could say whoop
I'm gonna do this is we could say oh if
it's delete
then result equals
um let's just say
so it is deleted
and then we can come back down here and
we can do else
of equals uh
at the not import
ant
so now if we come in and we can do let's
run this
and we're going to show you what some of
these are so if I could run this and I
come over here to my let's change my get
but instead of a get
these are all these little guys we can
do so if I'm going to come in so if I
said delete
method not allowed
oh because I haven't turned it on here
so this actually is already going to get
it to me so if I hit delete
but uh let me also do
oh let's just pick another one
let's do
oh
let's do a patch which is usually going
to be an update
so that would be a different one so
let's do that so let's do those three or
those four
so now if we run it
if we do a get
we're good
if we do a delete it's going to say
assume it's deleted if we do a patch
it's going to get through but it's going
to say it's not implemented
and if we do like say a purge
then it's going to blow up but it's
going to say it's not allowed
so you've got a quite a few things that
are used here and it's one of those
that's probably best to sort of see what
the you know the standards are
particularly for your your organization
as far as development standards and such
but you will see these fairly often used
at least you'll see get post put
patch and delete I see a lot
the others that sort of varies but
it's good to know they're out there and
to know that that's the difference is
that you can use the same API endpoint
and you can actually have several
different functions working off of that
as we're doing so that gives you a a
good dive into your gits or posts and
things like that we have gotten a lot of
functionality into our API and we'll
come back next time and we'll continue
on so thanks a lot we've got our post
get delete request types got those
things done and uh get some more done
next time so go out there and have
yourself a great day and we will talk to
you next time
thank you
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 enroll 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.develop anywhere always having a
little more of a educational format and
a way for you to track your progress as
you move forward becoming a better
developer
Transcript Segments
0.42

foreign

18.89

[Music]

27.42

well hello and welcome back we are

29.82

cruising along in our little shortener

31.619

application doing a series of questions

33.78

and answers basically to get you through

36.66

some key things so basically we're going

38.88

to do here is we're going to talk a

40.44

little bit about we've got ourselves so

42.6

we've got an API that we're calling from

44.219

python

46.379

we are now going to talk a little bit

48.059

about get and post and deletes and

51.78

request types A little bit really more

54.3

uh the getting the posts and just sort

56.34

of how these things work and what you

59.039

should be doing to actually craft like a

61.92

decent API call because what we've got

63.84

right here

65.1

just kicks out if you see it when we do

67.439

calls it just kicks out some nice big

70.5

texty thing which is really not

72.72

generally useful I mean you can see it

74.28

here is it's just here's your text what

76.799

we really want is something that is more

79.4

workable because our raw notice is the

82.74

same as our pretty

84.54

and we're jasonifying stuff

87.479

when we don't really have a need to so

89.759

what you normally want to do

91.439

is you're going to have something in

94.2

your message that you're going to send

95.64

back so we're going to change up our API

98.759

this time

100.619

and what we're going to do

102.78

is we're going to actually start working

104.22

on this a bit so instead of

107.579

uh let's see do I want to call that

112.2

I'm trying to think if I want to go

113.159

ahead let's go ahead

114.96

and we'll come back to this another time

116.64

because I know I was going to hook the

117.96

whole thing up but

122.52

uh I could probably do that pretty quick

124.02

okay

125.06

so let's see

130.14

um

136.92

yeah I can probably do this so let's try

139.44

this

141.66

so here's what we're going to do

144.12

so we've got a little database

146.099

set up

147.42

we got a couple calls so we're going to

149.52

go to shorty

151.08

and over here

153

we're going to import

156.84

or actually how does it look uh it is uh

159.9

from DB create

166.819

whoops

168.48

import

173.36

my database I think that's what I want

176.22

to do

177.3

whoop

178.62

my database there we go

180.66

so now what we're going to do here is we

182.94

don't have to worry about our counter

183.9

anymore

185.099

but we do want to do is

189.12

we're going to actually let's do in a

193.08

knit

200.28

and take all of that

203.519

like this

205.019

and so let's see we're gonna set up our

207.239

database we don't need to create one

210.54

there's a database name we're going to

212.7

pull oop import

217.319

uh

223.92

let's do

229.58

this we're going to change this around a

232.86

little bit

240.9

so we're going to come in here

244.2

and we're going to do this

249.48

take that I'm going to come over here

254.04

so first thing we want to do is we're

255.299

going to set up we're doing a little bit

256.739

of changes here is we're going to come

258.66

in and we're going to set up our

260.28

database

267.12

we're going to get here

270.66

we're gonna get his name I think that's

272.52

all we need here

274.8

we don't need to create a table uh we

277.74

don't need rows

281.699

oh we do want to steal one of those

283.919

calls insert record links okay so those

285.66

are the ones we're going to need so we

287.1

need

289.22

searches and then we've got a connection

291.36

that we don't need to worry about right

292.8

now

297.66

let's do this

301.44

so we're going to use its Constructor

304.139

which means we create this shortener

306.54

it's going to go through these things we

308.4

don't need it to go through these

312.72

so let's do that

316.139

and now what we want to do is so

318.78

navigate

320.88

is going to be

323.52

just going to do a retrieve link

326.52

based on the number

328.62

so here

333.6

he's going to do

338.46

uh let's do my DB

341.78

uh let's do this

349.979

and I'm going to do my DB connect which

351.96

is a

352.88

self.idb Connect

359.34

and then this is going to be

362

self.idb dot retrieve link based on the

365.639

idx

371.58

that

375

and then we're gonna do we're gonna do

376.919

message

382.319

well we're gonna do this we'll do that

384.3

afterwards so we're gonna do uh let's

386.4

see

390.06

what's that

392.039

we're gonna return

395.16

the message but the message is going to

397.979

be

404.819

and it's going to be status

408.06

is status

410.22

and

412.259

data

414.3

is

416.28

whoops

417.72

pan data

420.24

is result

424.319

the result there we go status

437.639

we're going to do this we're going to

439.68

try that

442.08

we're going to do this sort of simplify

443.759

but and I will walk through this in just

445.979

a second except if I can spell it right

450.599

and then here

452.34

status equals error

457.259

their status

459.68

SQL status there we go real life results

464.039

you probably don't like that

473.34

a variable annotation cannot be combined

475.259

with Tuple unpacking okay I'm not sure

477.419

what that means we're gonna find out in

478.74

a second

482.16

oh

483.479

it probably needs to be this maybe

485.099

that's what it likes

495.18

okay let's try that so retiring light

498

retrieval ain't uh yeah okay

503.879

so that gives us our Link in the

507.36

database

510.18

let's see is it going to complain uh

514.2

probably

516.24

yeah invalid status so we need this to

519.599

be oh

521.88

because I did that wrong

525.42

there we go

526.8

uh and so let me go ahead and get this

528.72

one done while I'm at it

530.399

we're gonna do basically the same thing

531.779

so here when we retrieve New York URL

535.26

um

536.58

our return value so we need to insert a

539.1

record link

543.839

easy because that's going to be

546.48

Health Dot

548.399

and then return value

552.06

let's say that well let's just do this

555.72

it's going to look about the same

563.76

let's take that we're going to look

565.26

about the same we don't need to close

568.86

or return the message

571.92

what we're going to try is this

580.019

and he's instead going to be

585.36

uh

592.2

oh here it's looking for a code that's

595.38

right so before we're going to give it a

597

code

597.899

so let's go look back here at

603.019

dbcreates when it does

608.64

or did we do that

610.62

create database create table list tables

613.62

list rows insert record links here we go

618.24

so we were going to give it a number

622.68

and let's do

627.06

let's do this

629.04

we're going to actually get a little bit

630.779

funky here so

633.06

we're gonna get uh

638.64

let's just do this uh we're gonna we're

641.58

gonna cheat for now

643.26

uh no we're not okay I was going to but

646.92

let's we'll come back to this so let's

649.019

do uh get next number

654.72

and this one's gonna be really simple

655.98

because all we're going to do is we're

658.14

gonna let's see here here

661.86

and we're going to do select Max ID

666.66

plus one

668.76

from links

674.64

and then

677.579

this

682.38

and let's see result oops

687.959

so here we're going to do we can do

690.54

because before we did a fetch all we saw

692.88

this

694.079

here we're going to do effects one so we

696.899

don't need to commit

699.66

so we're going to do row equals fetch

702.24

one

705.06

and then

710.16

let's see we're going to do ID equals oh

714.06

let's do yeah we'll do uh we'll call it

716.279

result

717.54

so it equals zero here

721.019

the result equals negative one

724.68

we're gonna print that we're going to

725.94

return the result

730.8

and this is going to be result

735.959

because if we fetch one and it's going

737.399

to be zero because we want the first row

741.12

uh probably is going to get overwritten

743.339

so we can get away with it but we're

744.72

gonna let that go anyways okay so that's

746.04

gonna be getting X number so when we go

747.54

to shorty uh here we're gonna set our

750.72

counter so we're gonna do uh we're just

753.6

gonna call it

755.76

style equals

757.74

self Dot mydb

760.98

dot get next number

763.98

and then here

766.139

the return value is just simply going to

768.36

be the base

770.459

Plus

772.5

that

774.6

but then we need to save it

779

uh which I think we're gonna be okay

782.579

so that's our return value and so here

788.519

we need to take oh this actually

790.98

simplifies because now this is going to

792.42

be the return value which is the um

798.18

the URL the short URL and then the next

800.7

thing is going to be the next vowel

802.62

because that's what our code is

806.639

and then a one because oh because that

809.279

was our user so I have to worry about it

811.98

and then we have a result okay boom so

815.22

now we have Rewritten these things to be

817.44

something a little more useful

819.24

should run okay so let's go look at

821.459

these real quick so if we go

823.74

and do a post

826.019

of this

829.8

oh and shorty

832.019

status equals error oh here we go I

834.3

forgot to put that there oh which we

836.16

also forgot

839.519

uh uh here no

842.16

here

845.82

we want this to be

849.06

oh shoot

855

shorty doesn't really need to do this

857.04

because he's

859.62

we really want him to be on the API okay

861.72

my mistake uh but let's do that anyways

865.26

so what we're going to do now is we're

866.88

going to pass those through so now

868.98

uh this is the so retrieve new new URL

874.2

is the result

878.399

and then here result

881.579

and then here we're just going to dump

882.959

the results so now normally we're going

885.42

to do this somewhere else but we'll do

888.72

these here because that'll just allow us

890.399

to get that done

891.959

so now if we run this

893.88

and we come here and run our post first

898.139

then okay data is three oops we did not

901.74

want that to be three we wanted our AP

905.339

um

908.639

when we add a link

916.04

uh let's see

919.139

insert record link which means over at

921.48

Shorty we didn't want it to be the

923.76

return value oh yeah

927.18

self.base

930.12

plus next vowel

934.8

oh data is oops my bad

938.639

that needs to be return value

947.94

because

950.88

yes that's going to be successful

956.88

insert record links doesn't give

958.38

anything oh because that's the new

961.8

and we're going to call we'll do this

963.839

um

966.54

uh let's call that new ID

970.56

and that'll be result

973.5

otherwise result is zero

977.279

let's do that for fun

979.92

okay so that is shorty let's get him

982.32

here

983.699

if we do that

987.959

let's get rid of that so now if we run

990.54

it

991.62

uh so that was three this is probably

993.12

gonna be something else okay so four so

995.82

now if we take that

999.48

and see that's like the pretty version

1001.04

Raw it's actually about the same

1004.3

but now we're getting something that we

1006.44

can actually work with we can do

1007.699

something with this on the other side of

1009.38

it

1010.12

so shorty uh get

1014.779

and so if I do

1019.519

four

1021.079

then he's going to send that back and so

1023.48

now in my

1025.939

app

1028.22

my caller I can actually do something

1030.86

with this so now my response I'm going

1032.36

to get something and I'm going to get my

1033.919

response dot text

1036.62

and let's go look at the same thing uh

1039.86

so let's see

1043.04

so what you already wish to use let's

1045.079

use this big one

1051.98

and so now

1053.84

uh

1055.14

[Music]

1058.94

in that literal for INT so what do we do

1061.46

here

1063.919

oh

1067.94

Oops I did that reverse order

1071.299

so I want this to be this guy

1075.799

wait right yeah

1080.96

okay

1082.82

and so now I can see that I've got data

1087.08

and

1088.76

let's see which short URL do you want to

1090.799

shorten if I take this big one

1096.14

I've got that

1098.72

but now I can take the same thing

1101.78

and let's go change it now so that when

1104.419

I do

1106.46

caller

1108.32

let's see what he wants to do instead

1112.46

because he's going to do response.text

1116.9

and he's going to be so the shortened

1118.88

URL is actually

1121.94

uh uh the data

1124.76

so let's see how that works

1127.46

let's see if we do that now

1129.32

we do that for short

1137.26

uh is it not printing out what I wanted

1139.82

it to

1143.36

oh yes

1145.64

that's the problem

1152.419

not worry about shortening one

1157.299

and let's see which I already wish to

1160.52

use

1163.16

oh so this is because of the way it's

1166.22

set up so data is what was Data data was

1169.52

two I think

1173.12

data is one okay

1178.4

so it's this just because of what we're

1180.5

doing so if we do it this way

1184.28

and we do it this way let's see what

1186.86

that looks like

1189.14

so now if we do it

1191.059

it gives us an empty oh we want

1194.78

zero let's try that

1202.22

whoop

1206.059

oh

1207.919

let's do this

1210.5

super spots

1213.08

data

1220.94

uh response object is not subscriptable

1223.76

so we did not do what we wanted to with

1226.7

this

1233.2

so let's take a look here so we got that

1235.94

that's our payload should be that

1240.08

um

1243.62

our API is going to send back

1248.36

that so our call

1259.1

is that

1266.12

uh let's see what did we miss here

1273.32

what was it complaining about it said it

1275.059

didn't like

1276.38

response object is not subscriptable so

1279.02

let's go look at response real quick uh

1281.48

let's do that

1287.48

oh

1288.86

we need to do

1291.98

uh

1293.9

where is it

1300.28

response.data let's go see

1309.98

let's go look at him again

1316.7

so that's response is 200.

1325.94

so if we go look here

1333.98

I wonder if that is the wrong

1337.059

brackets that I wanted to use

1341.419

huh I think so

1343.28

okay my mistake I was doing a dump to a

1345.98

string I need to do a jersonify so now I

1349.88

see something makes a little better

1351.02

sense and then

1354.02

uh Where'd I go over here

1356.84

so now if I do oops I don't want shorty

1359.659

I want the collar

1361.64

uh so if he does response

1365.059

uh well let's look at that first if I

1367.28

look at that

1369.679

uh if I shorten

1374.3

[Music]

1378.679

okay there's my response

1381.559

how to response dot data I think

1386.659

make sure I get this right

1388.58

um

1392.179

whoops

1394.94

uh it doesn't have that so if I do

1399.679

let's try a response well let's do

1405.5

next

1406.7

to that

1410.24

oh dang it keep hitting the wrong key

1414.62

uh okay so there's the data and if I do

1417.799

response text

1421.1

data

1425.179

is that going to give me I think that's

1426.38

going to give me what I want

1429.98

ah

1431.96

there we go

1435.5

uh nope it must be an integer okay

1442.94

so it's not getting that back out one

1445.039

second

1445.88

okay we have to actually do this is

1447.74

where we want

1449

um

1449.84

let's see our cell equal Json dot loads

1455.5

uh oh am I in the right place

1459.82

that's not really where let's sit this

1462.98

way I want it here in the API because I

1465.44

already have it

1470.059

uh so I'm gonna jsonify the result

1474.44

oh and then the caller is going to need

1476

that so he's going to need an import

1480.32

Json

1486.08

and then he's gonna need from the

1488.36

response

1489.679

he's going to do there's no equals

1494.2

Json dot okay so that loads

1499.64

the response dot text

1504.5

and then I can do the result

1510.679

now I can do the result I'm going to

1512.78

call that data

1515.24

look at that

1520.34

and I think we're going to see here

1522.799

there we go and so now we're actually

1525.5

pulling this so we're putting a complex

1526.94

thing together that's we can check for

1529.039

like so here we can say

1532.159

um

1533.36

if oops I don't want to put it there yet

1535.76

so I want to come back here and we could

1537.14

say if

1538.46

results

1541.46

uh what did we call that

1543.74

we called it

1547.159

here

1548.48

status

1550.159

usually we're going to do this from the

1551.539

API we did it's a little different but

1553.22

if we take result status

1556.82

equals

1559.039

let's say not equal to

1562.88

success

1566.84

then

1568.4

return

1572.059

status

1579.38

there we go otherwise you're going to

1580.7

return the result

1583.4

so now we're going to get something like

1585.08

this so if we go here

1587.24

and we give it something bogus

1589.64

then it should oh it's going to blow up

1593.72

uh because we didn't put a try here wait

1596.779

uh

1602.059

let's do this

1604.34

let's just move him up

1609.279

uh who's that that is shorty so oops

1612.44

we're going to restart this

1614.779

start our API now if we do the call

1619.22

and give it something useless

1624.46

let's see

1631.279

oh results

1636.32

very good result equals negative one we

1639.26

got to set that up too

1641.6

so now

1643.159

let's try that one more time

1646.279

and let's just give it something that's

1647.84

bogus

1649.88

so now it's going to tell us an error so

1651.799

there you go so now we've actually added

1653

a little bit error checking to our API

1654.679

which is something you definitely want

1656.659

to do

1657.98

final thing is I did want to mention

1660.679

there's a difference between you have

1662.179

gits and posts and deletes and updates

1665.179

and things like that typically as we're

1667.7

seeing here is use a get to actually get

1670.159

a value

1671.539

from it's sort of like a list kind of

1673.82

thing post is usually going to be an

1675.38

update which is what we're doing here so

1676.88

when we're inserting our record we're

1678.74

going to do retrieve new URL

1680.48

otherwise if it's a get

1683.36

which really should be

1685.1

uh I'll have

1690.679

to get

1693.919

then well we're going to do that

1697.279

what we could do is we could say whoop

1701.419

I'm gonna do this is we could say oh if

1704.659

it's delete

1706.279

then result equals

1711.62

um let's just say

1715.76

so it is deleted

1719.179

and then we can come back down here and

1721.58

we can do else

1725.72

of equals uh

1728.779

at the not import

1731.659

ant

1732.919

so now if we come in and we can do let's

1736.64

run this

1738.32

and we're going to show you what some of

1739.82

these are so if I could run this and I

1742.1

come over here to my let's change my get

1744.14

but instead of a get

1746.179

these are all these little guys we can

1748.52

do so if I'm going to come in so if I

1750.5

said delete

1753.74

method not allowed

1755.779

oh because I haven't turned it on here

1758.299

so this actually is already going to get

1760.279

it to me so if I hit delete

1762.86

but uh let me also do

1766.76

oh let's just pick another one

1768.86

let's do

1777.26

oh

1778.58

let's do a patch which is usually going

1781.94

to be an update

1783.74

so that would be a different one so

1785.539

let's do that so let's do those three or

1787.46

those four

1789.679

so now if we run it

1792.76

if we do a get

1795.799

we're good

1797.12

if we do a delete it's going to say

1799.899

assume it's deleted if we do a patch

1803.24

it's going to get through but it's going

1804.799

to say it's not implemented

1807.02

and if we do like say a purge

1810.559

then it's going to blow up but it's

1811.94

going to say it's not allowed

1813.679

so you've got a quite a few things that

1815.84

are used here and it's one of those

1817.64

that's probably best to sort of see what

1819.62

the you know the standards are

1821.179

particularly for your your organization

1823.52

as far as development standards and such

1825.14

but you will see these fairly often used

1828.82

at least you'll see get post put

1833.2

patch and delete I see a lot

1836.679

the others that sort of varies but

1840.5

it's good to know they're out there and

1842.419

to know that that's the difference is

1843.62

that you can use the same API endpoint

1846.08

and you can actually have several

1847.64

different functions working off of that

1849.679

as we're doing so that gives you a a

1853.1

good dive into your gits or posts and

1855.26

things like that we have gotten a lot of

1857.899

functionality into our API and we'll

1859.76

come back next time and we'll continue

1862.039

on so thanks a lot we've got our post

1865.399

get delete request types got those

1867.02

things done and uh get some more done

1870.2

next time so go out there and have

1871.399

yourself a great day and we will talk to

1873.44

you next time

1884.74

thank you

1891.44

hello this is Rob with developmentor

1893.84

also known as building better developers

1895.94

wanted to announce that we have

1898.36

school.developmentor.com feel free to

1900.62

check it out if you like any of this

1902.779

information any of the content that

1904.7

we've sent and you would like to see

1905.899

more you can come out you can enroll for

1908

free we have free courses we've got

1910.279

places for you to get better at just

1912.919

learning a technology our how to's you

1915.62

can work on your business skills we can

1917.659

help you with becoming a better

1919.1

developer as encoding and things like

1921.5

that a lot of the stuff you've seen on

1923.179

YouTube we also have out at

1925.34

school.develop anywhere always having a

1927.62

little more of a educational format and

1930.14

a way for you to track your progress as

1932.659

you move forward becoming a better

1934.82

developer