How to Test REST APIs Faster with the REST Client Extension in VS Code
Show More Show Less View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video we will show you a new vs
0:05
code extension where you can actually
0:07
test your rest API directly inside V
0:11
Visual Studio code you don't need
0:12
Postman you don't need to leave vs code
0:15
you can directly create a rest file and
0:18
just make a get request or a post
0:21
request so let me just show you so this
0:25
is the request that we created we get a
0:27
send request button right here and and
0:30
on the right hand side you will get the
0:32
result after you make this request you
0:34
will get this Json response that you can
0:36
clearly see in the VSS code itself so
0:40
the extension name is rest
0:42
client and
0:44
uh if you go to the extensions type just
0:47
type rest client let me uninstall it and
0:52
install it once
0:54
again so this is the extension it's a
0:57
rest client for visual studio code
1:00
and it has got almost 5.1 million
1:03
downloads it's a very popular extension
1:06
so many of times you need to test out
1:08
rest apis while you are developing or
1:11
test out third party apis so this
1:14
extension may be useful for that
1:15
purposes so click on the install button
1:18
so it will be installed globally inside
1:20
your system so now to use this extension
1:24
we do need to
1:25
create a rest file so just create sample
1:30
do rest file so the name can be anything
1:33
but the extension need to be rest so
1:36
just put a rest extension and just
1:39
create this file so right inside this
1:41
file
1:42
so we can just write a simple comment
1:45
that we are making a get
1:49
request here you can just write some
1:51
sample description we fetching users
1:54
from Json placeholder API so here the
1:56
method will be get so as soon as you
1:59
write the method get right here you will
2:01
see this button right here send request
2:03
button and here you now need to provide
2:06
the URL to which you are making the get
2:09
request so we will be using this Json
2:12
placeholder API typo code.com
2:17
users so this will fetch the users in a
2:21
Json response and here we do need to ex
2:24
provide the content type so
2:26
accept and we will be accepting the data
2:29
so you can see various dropdowns various
2:32
suggestions are coming either you can
2:34
accept in gzip JavaScript Json so
2:37
typically the data from rest apis will
2:40
be coming application SL
2:42
Json so now we can simply click on the
2:46
send request button so as soon as you
2:48
click this button you will see on the
2:49
right hand side the Json response has
2:51
come from the third party API right in
2:54
the vs code itself you don't need to
2:57
leave vs code and and simply you can see
3:01
the data coming from the rest API so
3:04
this is a really useful extension and uh
3:07
now if you want to make a post request
3:09
you need to just
3:11
change let me change this to a post
3:14
request for creating a
3:19
user so here we'll simply change the
3:21
method name from get to
3:24
post and the URL will remain constant
3:28
but this time content type we need to
3:31
say content type because we will be
3:34
passing a user so here you simply need
3:36
to say content
3:38
type and then application SL Json so
3:42
this drop down makes it really easy so
3:45
if you basically forgot you can see in
3:47
the drop down
3:48
suggestions this extension makes it
3:50
really easy to send out these rest API
3:54
request and here need to pass a user
3:57
that needs to be created so it will have
3:59
three properties the name of the
4:05
user then we just need to provide the
4:08
username
4:11
property and the email
4:16
property so have Pro provided these
4:19
three properties we are sending a simple
4:21
post request to this rest API so if I
4:24
click the button send request and now
4:27
you will see the 2011 status code is
4:30
returned to us which is means the record
4:32
has been created and all search
4:35
information content type content length
4:37
connection all this information is
4:39
returned to us you can see
4:41
that the date of the request this is the
4:45
expiry date so now if you see the
4:48
response that user is successfully
4:50
created and ID is returned to us which
4:54
is the unique ID which is assigned to
4:56
it which is name username email that you
4:59
provide it so this is actually a very
5:03
good extension guys you can try out with
5:05
any API which is there you just need to
5:08
know the URL of it just create a rest
5:11
file provide this method here paste the
5:13
URL and then you can make any
5:18
request so similarly we do have other
5:22
types of request as well so if you want
5:24
to delete a user you will simply say
5:27
delete
5:31
so instead of post we will simply say
5:39
delete so here we don't need to provide
5:42
this we just need to provide the ID here
5:44
so we need to delete the first user so
5:47
we will passing the ID right here which
5:49
is a query parameter right here so it
5:53
will delete the first user so if I click
5:55
Send request 20 200 status code is
5:59
returned to us so the that user is
6:01
successfully deleted and you will
6:03
actually get an empty response so that
6:05
user is successfully
6:08
deleted and similarly you if you want to
6:11
update a user so four four operations
6:13
are there in rest API either you can
6:16
read user delete user create user and
6:18
update the user and for updating it we
6:21
can either make a put
6:23
request so this time we will update the
6:26
user
6:32
so for updating it is a patch or put so
6:36
you can use a put
6:38
request and say will be updating the
6:41
first user so we are providing the ID
6:43
right here as a query parameter and then
6:45
we do need to provide the details of the
6:48
user again we need to
6:50
provide application SL Json so now to
6:55
update the user we'll again provide that
6:57
object which will contain these three
6:59
proper name username email so we
7:02
provided these updated details so if I
7:05
send the request so now the the that
7:08
user will be updated with these details
7:10
that we provided the ID will be returned
7:13
to us and uh 200 status code again it is
7:16
return returned so in this way you can
7:18
make all the four operations in rest API
7:21
with any API in vs code using this
7:24
extension so it's a very nice extension
7:27
I personally use this extension a lot
7:29
while we develop apis or I use any sort
7:31
of apis so it's a great extension you
7:34
must install it so and thank you very
7:38
much for watching this video and do
7:40
check out my website as well freem
7:42
mediat tools.com
7:45
which contains thousands of free tools
7:47
related to audio video and image and I
7:50
will be seeing you in the next video
#Internet Software
#Development Tools
