📺 Develpreneur YouTube Episode

Video + transcript

Swagger With Python Part 3

2023-10-12 •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 looks at some ways we can embrace documentation and make the API more useful to others through details and examples in our docs.

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 little short API
shortener or URL shortener API
application thing my Jake um I know I'm
getting a little technical there but
basically you give it a URL it gives you
a short one back just like bitly or owly
or any of those other ones what we're
doing right now is in a we're going to
wrap up talking about the Swagger uh API
documentation piece because that's
pretty darn useful uh just to catch you
up as we have you know a nice document
that has been created for us that we can
you gets thrown out on a so somebody can
take a look at
our API and actually put it to use now a
few extra things we have not talked
about first one is there are Swagger
things that you can do so if I just like
get rid of these these which I've been
using then what you're going to see
right away you're going to see this page
looks different when I first refresh it
because boom it is not expanding it also
if I do
get uh try it out if I get hello then
it's just going to say hey here it is
here's response headers what I was
using there we go is one that I'm going
to expand the list and then I'm also
going to have a request duration and an
operation ID and these I got we talked a
little bit of last time about chat
GPT and how it can maybe help you out
well that one I did how do I add extra
content descriptions to flask uh rest X
Swagger documentation and boom I do this
and it gives me a bunch of nice little
information things that we can look at
so it's a quick way to be like oh hey
how do I do this and we're gonna talk
through that so this one now when we go
back after we add just those couple
now wh I got to restart the API that
usually helps come
here so now when I run it because I said
automatically blow it out it's going to
blow out all of the uh it gives you the
full list here it also now when I run
like get hello try it out execute so we
didn't see before is I get a little
request duration so I can see how long
it took to run this thing which can
sometimes be very useful so if I wanted
to like uh get a shortened
one try it out
whoops and I do HTTP colon backb DP link
dot
us I think it's this way how did I write
that yeah and give it like a I don't
know
13
then it's going to come through and it
gives me this and I can see here's my
request duration so I get a couple extra
things you can get to your um you your
displays depending on how you want to do
it it's a it's not a big deal
necessarily
however some things that are more would
be each of these um is that we can do is
we can come in and we can do and I
believe it is below I want to make sure
where the comments go
yeah you can do and this is probably
going to feel a little bit familiar you
may have seen this before you can
actually triple comment stuff so I can
come in here and go one two three there
we go and in here so I can say like see
this even gives me like return uh
string that API is up if it
is and this is just to check if the API
is
up uh user will get an error
otherwise there we
go and let's do like the
git so here we're going to say this is
going to
return the
um uh
Json packet of results and so if I do a
git let me do it like this is if I do
the G where's the G there's the git oh
that's the wrong one uh this is the
short and
git I'm going to say
this that has a resultant status oh that
has data and
Status such as the example below which I
think did it already give me that
somewhere
um no it doesn't so good so I can put
that there and say this is what it looks
like
wh let's do that there and this is
uh takes a URL
par URL
equals
of
the HTML
address HTTP
Co DPL link.
us quote And
Then
followed by an ID to R turn
string a let's see a full URL
okay and so let's just go with those
two and what we will see now
is we pull this in if we look at
hello so here we can see that now I've
got a comment sitting in here so uh that
first line let's see
hello where is that so this is just a
check there you go it does that uh just
just to check if the API is up user will
get an error otherwise and notice it
sort of rolls over and then uh return
string that API is up if it is so we get
something sort of useful
there and down
here
forget so the same kind of thing takes a
URL pram URL of the
HTML
htlm which we can actually clean this up
a little bit um
uh that's
HTML so we're going to get let's say uh
get the full
URL from the shortened
one and so now what we
get
um
the
user or they will get an error otherwise
okay so now if we take this so now we
can clean it up a little bit and it's
going to look a little bit better
because now what we've got here is get
the full URL from the shorten one and
then it says here's what it is return we
can actually put you know a decent
amount of information in there we can
actually get a little bit more
complicated as we want to uh up here
this is the uh yeah if we remember we
had the full
description um and we had this we could
actually do I
think maybe let's see what happens if we
do a triple
here and instead do it like
this and let's change our description
actually let's do
two uh let's see
let's do
this um let's say October
2023 let's do that and let's see how
that
looks so now we're going to look at the
top and we're going to see there you go
so it does it also gives us something
similar here that we can get into it and
and get fairly complex and have you know
a nice set of document M ation uh these
things obviously it's a little better to
have your little uh you know sort of a a
brief summary type title
row and again with in doubt go chat GPT
it up and then see what comes because
you're going to see you know some pretty
good information like here um I
could come in here and I could actually
look a little deeper into this one with
additional metadata so I could
do let's just do this so if I want to go
into those settings a little bit more
now I'm going to get something that's
going to be a little
more let's see um oh and I guess it
gives me maybe that's the only ones
we've got um there is some
oh oh here we go so we can get some more
information here we got title
description contact and license we had
title
description um let's do this so let's go
look at those real quick so title we
had description we have
contact let's do
a uh let's
do
infomat preneur whop if I spell it right
develop preneur
docomo free to
use let
us how
to improve it there we go so if we look
at
that then we're going to
see something like
this uh it doesn't oh it's not sh me a
whole oh yeah so it doesn't really say
that it's a
license um nor does it say contact
information which is interesting enough
so it may be an old version of it or
something along those lines
um so we'll have to see maybe chat GPT
doesn't know what the heck it's talking
about uh that could be part of the case
uh so if I do H I'm not going to go into
it but you could you could do like this
and then go expand three like and you
could get some more
information on maybe the additional
pieces that you can add things like that
so that will wrap this one up uh We've I
think we've spent enough time now that
you should have a good idea of how to
jump into Swagger and document your
stuff and it looks let's face it it's
it's not hard it looks good it doesn't
take you that long at all to add a
little bit extra comments and stuff and
then suddenly you've got something that
looks instead of like we originally did
that looks very hacky like this actually
starts looking you know pretty like
professional and stuff and you can have
real information and have things like
the the git where you can have like hey
it's going to look something like this
and there's additional things you can do
within swager to like highlight those
and and that kind of thing so that it
makes it pop as a document
goes that will wrap this one up uh we
will come back next time and we'll just
uh keep diving into things that we have
learned that being said go out there and
have yourself a great day thanks a lot
for your time and we'll talk to you next
[Music]
time
Transcript Segments
1.78

[Music]

10.16

well hello and welcome back we are

12.08

continuing our little short API

14.2

shortener or URL shortener API

17.8

application thing my Jake um I know I'm

20.039

getting a little technical there but

21.56

basically you give it a URL it gives you

23.32

a short one back just like bitly or owly

26.08

or any of those other ones what we're

29.24

doing right now is in a we're going to

30.8

wrap up talking about the Swagger uh API

33.76

documentation piece because that's

35.76

pretty darn useful uh just to catch you

38.04

up as we have you know a nice document

41.32

that has been created for us that we can

43.879

you gets thrown out on a so somebody can

45.68

take a look at

46.879

our API and actually put it to use now a

51.559

few extra things we have not talked

53.199

about first one is there are Swagger

56.32

things that you can do so if I just like

59.32

get rid of these these which I've been

63.32

using then what you're going to see

65.199

right away you're going to see this page

66.4

looks different when I first refresh it

68.52

because boom it is not expanding it also

72.64

if I do

74

get uh try it out if I get hello then

78.04

it's just going to say hey here it is

80

here's response headers what I was

84.64

using there we go is one that I'm going

88.079

to expand the list and then I'm also

90.799

going to have a request duration and an

93.36

operation ID and these I got we talked a

95.84

little bit of last time about chat

97.92

GPT and how it can maybe help you out

100.479

well that one I did how do I add extra

104.56

content descriptions to flask uh rest X

107.84

Swagger documentation and boom I do this

110.56

and it gives me a bunch of nice little

112.56

information things that we can look at

115.159

so it's a quick way to be like oh hey

116.88

how do I do this and we're gonna talk

119.36

through that so this one now when we go

122.96

back after we add just those couple

125.92

now wh I got to restart the API that

129.399

usually helps come

134.28

here so now when I run it because I said

137.519

automatically blow it out it's going to

138.959

blow out all of the uh it gives you the

140.8

full list here it also now when I run

143.56

like get hello try it out execute so we

148.44

didn't see before is I get a little

150

request duration so I can see how long

152

it took to run this thing which can

153.959

sometimes be very useful so if I wanted

156.519

to like uh get a shortened

160.72

one try it out

163.72

whoops and I do HTTP colon backb DP link

170.68

dot

172.56

us I think it's this way how did I write

175.239

that yeah and give it like a I don't

177.68

know

178.76

13

181.92

then it's going to come through and it

183.44

gives me this and I can see here's my

185.04

request duration so I get a couple extra

187.4

things you can get to your um you your

190.12

displays depending on how you want to do

191.92

it it's a it's not a big deal

194.12

necessarily

196

however some things that are more would

199.2

be each of these um is that we can do is

203.159

we can come in and we can do and I

206.08

believe it is below I want to make sure

207.84

where the comments go

211.239

yeah you can do and this is probably

213.519

going to feel a little bit familiar you

214.799

may have seen this before you can

215.879

actually triple comment stuff so I can

217.239

come in here and go one two three there

219.64

we go and in here so I can say like see

223.239

this even gives me like return uh

230.159

string that API is up if it

236.04

is and this is just to check if the API

243.599

is

245.56

up uh user will get an error

251.319

otherwise there we

253.64

go and let's do like the

259.32

git so here we're going to say this is

261.759

going to

262.8

return the

266.199

um uh

268

Json packet of results and so if I do a

272.12

git let me do it like this is if I do

274.199

the G where's the G there's the git oh

277.12

that's the wrong one uh this is the

280.639

short and

283.44

git I'm going to say

287.52

this that has a resultant status oh that

292.199

has data and

295.08

Status such as the example below which I

300.28

think did it already give me that

303.039

somewhere

305.08

um no it doesn't so good so I can put

307.96

that there and say this is what it looks

310.68

like

314

wh let's do that there and this is

318.639

uh takes a URL

325.08

par URL

328.479

equals

330.919

of

331.88

the HTML

335.759

address HTTP

339.759

Co DPL link.

343.56

us quote And

347.12

Then

349.84

followed by an ID to R turn

357.96

string a let's see a full URL

365.639

okay and so let's just go with those

368.319

two and what we will see now

371.88

is we pull this in if we look at

374.919

hello so here we can see that now I've

378.639

got a comment sitting in here so uh that

381.56

first line let's see

383.68

hello where is that so this is just a

385.88

check there you go it does that uh just

390.08

just to check if the API is up user will

392.8

get an error otherwise and notice it

394.08

sort of rolls over and then uh return

397.44

string that API is up if it is so we get

400.56

something sort of useful

402.96

there and down

406.44

here

408.479

forget so the same kind of thing takes a

410.919

URL pram URL of the

413.319

HTML

415.12

htlm which we can actually clean this up

417.56

a little bit um

422.319

uh that's

427.319

HTML so we're going to get let's say uh

430.8

get the full

437.84

URL from the shortened

442.16

one and so now what we

446.36

get

448.319

um

456.52

the

458.52

user or they will get an error otherwise

461.599

okay so now if we take this so now we

464

can clean it up a little bit and it's

465.44

going to look a little bit better

466.919

because now what we've got here is get

468.639

the full URL from the shorten one and

470.639

then it says here's what it is return we

472.84

can actually put you know a decent

474.24

amount of information in there we can

476.039

actually get a little bit more

477

complicated as we want to uh up here

480.36

this is the uh yeah if we remember we

482.479

had the full

484.319

description um and we had this we could

487.56

actually do I

490.4

think maybe let's see what happens if we

493.52

do a triple

496.52

here and instead do it like

501.56

this and let's change our description

503.879

actually let's do

507.56

two uh let's see

512.76

let's do

515.56

this um let's say October

521.68

2023 let's do that and let's see how

524

that

526.2

looks so now we're going to look at the

528.32

top and we're going to see there you go

530.279

so it does it also gives us something

531.92

similar here that we can get into it and

534.56

and get fairly complex and have you know

537.44

a nice set of document M ation uh these

540.44

things obviously it's a little better to

541.8

have your little uh you know sort of a a

544.44

brief summary type title

546.24

row and again with in doubt go chat GPT

550.959

it up and then see what comes because

552.88

you're going to see you know some pretty

554.519

good information like here um I

558.24

could come in here and I could actually

560.2

look a little deeper into this one with

562.56

additional metadata so I could

568.12

do let's just do this so if I want to go

572.2

into those settings a little bit more

574.6

now I'm going to get something that's

575.68

going to be a little

577

more let's see um oh and I guess it

580.399

gives me maybe that's the only ones

581.56

we've got um there is some

586.16

oh oh here we go so we can get some more

590.079

information here we got title

591.36

description contact and license we had

594.12

title

595.64

description um let's do this so let's go

599.8

look at those real quick so title we

602.72

had description we have

609.36

contact let's do

611.6

a uh let's

613.839

do

616.44

infomat preneur whop if I spell it right

620.079

develop preneur

628.04

docomo free to

630.12

use let

632.079

us how

634.48

to improve it there we go so if we look

637.8

at

639.68

that then we're going to

642.76

see something like

645.639

this uh it doesn't oh it's not sh me a

648.36

whole oh yeah so it doesn't really say

649.959

that it's a

650.88

license um nor does it say contact

654.12

information which is interesting enough

656.48

so it may be an old version of it or

658

something along those lines

662.079

um so we'll have to see maybe chat GPT

664.24

doesn't know what the heck it's talking

665.6

about uh that could be part of the case

669.6

uh so if I do H I'm not going to go into

671.399

it but you could you could do like this

673.2

and then go expand three like and you

675.88

could get some more

678.24

information on maybe the additional

680.639

pieces that you can add things like that

683.8

so that will wrap this one up uh We've I

687.279

think we've spent enough time now that

689

you should have a good idea of how to

690.36

jump into Swagger and document your

693.44

stuff and it looks let's face it it's

696.24

it's not hard it looks good it doesn't

699.48

take you that long at all to add a

700.76

little bit extra comments and stuff and

702.24

then suddenly you've got something that

703.24

looks instead of like we originally did

705.32

that looks very hacky like this actually

707.36

starts looking you know pretty like

709.68

professional and stuff and you can have

711

real information and have things like

713.56

the the git where you can have like hey

715.48

it's going to look something like this

717.24

and there's additional things you can do

718.56

within swager to like highlight those

720.279

and and that kind of thing so that it

722.8

makes it pop as a document

724.88

goes that will wrap this one up uh we

727.399

will come back next time and we'll just

729

uh keep diving into things that we have

730.68

learned that being said go out there and

732.44

have yourself a great day thanks a lot

733.88

for your time and we'll talk to you next

739.48

[Music]

747.88

time