📺 Develpreneur YouTube Episode

Video + transcript

Swagger With Python Part 2

2023-10-10 •Youtube

Detailed Notes

This video looks at one piece of our URL shortener solution. We have an API that we built and want to be able to provide documentation easily. We do this by embracing Swagger. This tutorial focuses on how to handle posting values to a call and using Chat GPT to assist you in coding.

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
[Music]
well hello and welcome back we are
continuing our shortener our URL
shortner API series of tutorials and
related questions we're talking about
the uh documentation the Swagger using
swagger with flask rest rest X and using
that to generate our documentation now I
sat
around let's just say I ran into a bit
of a blocker and the blocker was this
post and this is what we're going to
focus on this time is we're going to
talk about really this this thing this
call with the others uh when we looked
at them am I running it yes I'm running
it when we looked at the other
calls for example the um
git so the short and Git it has a URL so
if we try it out we could give it a URL
code I don't even know uh let me flip
over to postman real
quick
[Music]
and uh
get and so uh this is what I want for
the
URL and if I come over here and give it
this and execute then it's going to run
this is the URL that sent across uh this
is the response actually as it came oh
I'm sorry here it is as it came back and
I I had given it some sort of bad URL
was the URL but there you go so there is
from the shortened URL
here we get this this is what the
original one was now if we change that
number to like a 12 I don't know how
many we have here uh so that one was
there that was a nice long
one actually happens to be the Swagger
documentation now the challenge
becomes when we do the
post it required a
form and if you look back here if you go
to the
Post sorry if this isn't I don't know if
I can blow this up real quick yeah we
can blow this up a little bit and so you
can read it a little
better uh so for the post is this the
post oh there we go shorty post then uh
within here there was a body that we
were sending it that was a form
essentially it was a form with a URL
field and then uh we give it a value
normally what we're seeing like if we do
the Git it was a query parameter string
so it was just something we were tacking
on at the end what I ran into and spent
a good little time walking around
circles on it was getting this to work
so that I could treat this within the
Swagger page as a form which would be
here so if I want to shorten it now uh
and I'll show you this in a minute so if
I want to shorten
um let me do like let me take this chat
open ey this big chat GPT thing we'll
put that there execute it and then it
comes back and gives us oh this is
something it said it cannot rep
understand so I just blew it up
somewhere let's try
[Applause]
this
test.com switch index.html let's give it
that oh and I ran into this again why
did I run into this
again because if I do it
here it works
fine okay
so let's go back and look over here so
the key here
is uh that it you need to add an
argument I went back and forth quite a
bit on this as far as how to get it uh
what its type is all that kind of stuff
and when I started looking around there
was 15 different ways that this had
issues and um basically finally ended up
jumping over into chat
GPT and and I asked it I said
hey
um I said here I want to
document a flask rest X API that
receives form form variables and so I do
that and uh if I go all the way down
here and then it's going to give me some
answers and this is one of those things
using uh chat GPT to help you through
some
stuff so here we go uh this one is a
model uh it sends a model
across which I ended up having a lot of
issues with
that uh and then this one let's
see here's a
post so that was expect user model I
want to do it with a let me change that
question a little
bit document that receives
a a form
variable it's actually should be how
to let's see what it gives us
here um let's do it this way
whop with ADD
argument
how to document
that add
argument and here we go this is the one
we
want I
believe yeah so we have a required
parser
so let's do expand on
four so here we
[Music]
go and this should hopefully give us
what we need so if we come into here and
we look at this let's make sure sure we
got
that and so if we look we have up here
oh we don't have request
parser so
then we can do
that which we're going to
do let's do that
here and so this is just going to be the
parser I
assume
let's make sure that's right come in
here and
then we should be okay let's see if this
works this one of those things that it
worked and now that I'm looking at this
it is not because it hates me so let
stupid
parser add argument I do it that
way now let's take a look at it so let's
go back out of
here go back over
here and if we look at the post
shorten we're going to try it out we're
going to give it a URL we'll just give
it this
URL
execute
browser or proxy Center requested the
server could not understand probably
because it doesn't like it in the
Json so let's go back
here let's go back to our earlier how
to if we look all the way at the top
let's look at that real
quick okay so does
that so if we do
just that but I think that's going to
be a problem yeah so that's the prams we
don't want the pams we actually want
it because we had our prams for our URL
but we don't want a pram we actually
want a
form and there it
is oh maybe we can do it this
way let's try that so let's
see uh here we do whoops we do
that and it's going to be
uh
URL enter the URL that to
convert and
then uh within
this
we're just going to do
that okay request
form let's try that that
get let's try
that let's see if it
works so it thinks it works
there and and
post try it
out let's just do that execute
it success okay so this comes through
and it gave us that now let's see if we
run
post and it works yay we finally got it
working and it was all mostly to the
help of chat GPT which is what I wanted
to sort of throw in here uh besides the
fact that we have
our our post now working and so all of
our others will work as well and it was
a pain in the butt to do that because
it's a slightly different one so again
um let's just do like get hello that
doesn't even need any if I try it out
boom API is up if I do um well that one
that was just a test one so if we did
get
shorten and we give it
oh let's try it out and let's give it
some value out of
the um nope that's the post I don't want
the post I want the don't save it uh
get
there I've send that across this one
comes through because it comes as a
parameter and boom we get our address
back so there you go a little bonus of
just we're really just focusing on
documenting the post and using chat GPT
we're going to come back we will wrap
this one up we're going to talk about a
few more things we can do some ways to
tweak our comments a little bit more and
wrap up this little mini Swagger Series
so go out and have yourself a great day
and we will talk to you next
time hello this is Rob with develop or
also known as building better developers
wanted to announce that we have school.
developer.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 how
how- toos you can work on your business
skills we can help you with becoming a
better developer as in coding and things
like that a lot of the stuff you've seen
on YouTube we also have out at school.
develop andur we just have it a little
more of a uh educational format and a
way for you to track your progress as
you move forward becoming a better
developer
Transcript Segments
2.28

[Music]

10.719

well hello and welcome back we are

13.44

continuing our shortener our URL

16.52

shortner API series of tutorials and

19.199

related questions we're talking about

22.119

the uh documentation the Swagger using

25.119

swagger with flask rest rest X and using

30.279

that to generate our documentation now I

33.96

sat

35

around let's just say I ran into a bit

37.52

of a blocker and the blocker was this

41.399

post and this is what we're going to

43

focus on this time is we're going to

45.28

talk about really this this thing this

49.8

call with the others uh when we looked

52.64

at them am I running it yes I'm running

54.879

it when we looked at the other

57.96

calls for example the um

63

git so the short and Git it has a URL so

66.119

if we try it out we could give it a URL

68.36

code I don't even know uh let me flip

71.119

over to postman real

74.6

quick

75.97

[Music]

77.6

and uh

82.079

get and so uh this is what I want for

85.72

the

87.64

URL and if I come over here and give it

90.52

this and execute then it's going to run

94.56

this is the URL that sent across uh this

97.04

is the response actually as it came oh

98.759

I'm sorry here it is as it came back and

100.84

I I had given it some sort of bad URL

102.96

was the URL but there you go so there is

105.399

from the shortened URL

107.96

here we get this this is what the

110.64

original one was now if we change that

112.36

number to like a 12 I don't know how

114.84

many we have here uh so that one was

117.159

there that was a nice long

118.84

one actually happens to be the Swagger

122.159

documentation now the challenge

124.799

becomes when we do the

128.84

post it required a

131.959

form and if you look back here if you go

135.92

to the

138.04

Post sorry if this isn't I don't know if

140.599

I can blow this up real quick yeah we

142.76

can blow this up a little bit and so you

144.56

can read it a little

148.36

better uh so for the post is this the

151.36

post oh there we go shorty post then uh

154.48

within here there was a body that we

156.599

were sending it that was a form

158.319

essentially it was a form with a URL

160.159

field and then uh we give it a value

163.48

normally what we're seeing like if we do

165.28

the Git it was a query parameter string

168.4

so it was just something we were tacking

169.76

on at the end what I ran into and spent

173.84

a good little time walking around

175.599

circles on it was getting this to work

178.68

so that I could treat this within the

181.68

Swagger page as a form which would be

184.92

here so if I want to shorten it now uh

188.799

and I'll show you this in a minute so if

190.12

I want to shorten

192.68

um let me do like let me take this chat

196.84

open ey this big chat GPT thing we'll

200.4

put that there execute it and then it

203.72

comes back and gives us oh this is

206.239

something it said it cannot rep

208.48

understand so I just blew it up

211.36

somewhere let's try

213.85

[Applause]

217

this

218.599

test.com switch index.html let's give it

226

that oh and I ran into this again why

228.599

did I run into this

230.959

again because if I do it

235.76

here it works

238.4

fine okay

242.519

so let's go back and look over here so

245.04

the key here

247.28

is uh that it you need to add an

249.799

argument I went back and forth quite a

251.4

bit on this as far as how to get it uh

255.64

what its type is all that kind of stuff

257.28

and when I started looking around there

258.68

was 15 different ways that this had

261.919

issues and um basically finally ended up

266.28

jumping over into chat

268.4

GPT and and I asked it I said

272.36

hey

275.6

um I said here I want to

280.52

document a flask rest X API that

283.759

receives form form variables and so I do

287.12

that and uh if I go all the way down

292.68

here and then it's going to give me some

294.8

answers and this is one of those things

296.919

using uh chat GPT to help you through

300.52

some

301.96

stuff so here we go uh this one is a

306.4

model uh it sends a model

309.039

across which I ended up having a lot of

311.24

issues with

312.4

that uh and then this one let's

315.759

see here's a

317.919

post so that was expect user model I

320.88

want to do it with a let me change that

324.44

question a little

328.479

bit document that receives

335.36

a a form

338.6

variable it's actually should be how

341.8

to let's see what it gives us

351.8

here um let's do it this way

355.96

whop with ADD

358.479

argument

362.36

how to document

364.479

that add

374.96

argument and here we go this is the one

377.28

we

379.599

want I

385.919

believe yeah so we have a required

388.4

parser

390.44

so let's do expand on

409.08

four so here we

410.96

[Music]

412.96

go and this should hopefully give us

415.44

what we need so if we come into here and

418.199

we look at this let's make sure sure we

419.759

got

422.8

that and so if we look we have up here

426.12

oh we don't have request

429.08

parser so

433.24

then we can do

435.52

that which we're going to

440.28

do let's do that

444.319

here and so this is just going to be the

446.56

parser I

448.319

assume

452.199

let's make sure that's right come in

465.44

here and

467.639

then we should be okay let's see if this

471.72

works this one of those things that it

473.68

worked and now that I'm looking at this

475.759

it is not because it hates me so let

479.12

stupid

480.199

parser add argument I do it that

484.24

way now let's take a look at it so let's

486.72

go back out of

492.199

here go back over

496.08

here and if we look at the post

499.319

shorten we're going to try it out we're

501.599

going to give it a URL we'll just give

502.96

it this

506.44

URL

508.24

execute

510.319

browser or proxy Center requested the

512.12

server could not understand probably

515.399

because it doesn't like it in the

522.479

Json so let's go back

526.48

here let's go back to our earlier how

536.08

to if we look all the way at the top

538.519

let's look at that real

550.32

quick okay so does

558.64

that so if we do

562.839

just that but I think that's going to

566.8

be a problem yeah so that's the prams we

569.6

don't want the pams we actually want

573.079

it because we had our prams for our URL

575.519

but we don't want a pram we actually

576.88

want a

586.399

form and there it

593.6

is oh maybe we can do it this

597.04

way let's try that so let's

601.079

see uh here we do whoops we do

606.64

that and it's going to be

609.839

uh

614.16

URL enter the URL that to

621.519

convert and

624.279

then uh within

628.04

this

631.8

we're just going to do

637.72

that okay request

641.68

form let's try that that

646.48

get let's try

649.279

that let's see if it

652.76

works so it thinks it works

657.88

there and and

660.079

post try it

665

out let's just do that execute

670

it success okay so this comes through

672.72

and it gave us that now let's see if we

676.56

run

678.16

post and it works yay we finally got it

681.56

working and it was all mostly to the

685.24

help of chat GPT which is what I wanted

687.56

to sort of throw in here uh besides the

690.12

fact that we have

692

our our post now working and so all of

695

our others will work as well and it was

698.16

a pain in the butt to do that because

699.959

it's a slightly different one so again

702.8

um let's just do like get hello that

704.519

doesn't even need any if I try it out

707.399

boom API is up if I do um well that one

713.16

that was just a test one so if we did

714.639

get

715.88

shorten and we give it

719.519

oh let's try it out and let's give it

722.519

some value out of

727.399

the um nope that's the post I don't want

730.32

the post I want the don't save it uh

735.04

get

739.32

there I've send that across this one

742.48

comes through because it comes as a

744.8

parameter and boom we get our address

746.959

back so there you go a little bonus of

751

just we're really just focusing on

752.44

documenting the post and using chat GPT

756.72

we're going to come back we will wrap

758.079

this one up we're going to talk about a

759.199

few more things we can do some ways to

761.16

tweak our comments a little bit more and

763.72

wrap up this little mini Swagger Series

767

so go out and have yourself a great day

768.519

and we will talk to you next

771.279

time hello this is Rob with develop or

774.32

also known as building better developers

776.88

wanted to announce that we have school.

778.8

developer.com feel free to check it out

781.72

if you like any of this information any

784.36

of the content that we've sent and you

785.72

would like to see more you can come out

787.6

you can enroll for free we have free

789.6

courses we've got places for you to get

792.44

better at just learning a technology how

794.839

how- toos you can work on your business

796.8

skills we can help you with becoming a

799.36

better developer as in coding and things

801.8

like that a lot of the stuff you've seen

803.44

on YouTube we also have out at school.

806.32

develop andur we just have it a little

808.12

more of a uh educational format and a

810.639

way for you to track your progress as

813

you move forward becoming a better

815.519

developer