0% found this document useful (0 votes)
52 views

Tutorial 2 - The Rest Client: SOEN 487 - Web Services and Applications By: Nicholas Nagy

This document provides an overview of using a REST client to make HTTP requests to a REST API. It discusses the basics of REST and stateless communications. It then demonstrates making GET, POST, and DELETE requests using the Apache HTTP client and handling responses. Finally, it briefly introduces the Web Application Description Language (WADL) for documenting REST APIs.

Uploaded by

Brent Liang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Tutorial 2 - The Rest Client: SOEN 487 - Web Services and Applications By: Nicholas Nagy

This document provides an overview of using a REST client to make HTTP requests to a REST API. It discusses the basics of REST and stateless communications. It then demonstrates making GET, POST, and DELETE requests using the Apache HTTP client and handling responses. Finally, it briefly introduces the Web Application Description Language (WADL) for documenting REST APIs.

Uploaded by

Brent Liang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Tutorial 2 - The

Rest Client

SOEN 487 - Web Services and Applications


By: Nicholas Nagy
What is a REST API? - Recall

- REST is an acronym for


REpresentational State Transfer.
- It helps abstract the client away from
the server and provides a means for
them to communicate.
- All communications are stateless, so
they need to contain all the required
information to understand the
request within them.
- More Restful API Notes

Winter 2021
Instructions to Follow Along

Please download the source code at the following link:

https://github.com/SOEN487/T02

Or

Add the following dependency to the previous tutorial’s source files (in the dependencies tag)
and create the corresponding classes defined in this tutorial:

Winter 2021
Apache HTTP Client Request Breakdown

Winter 2021
Customer Rest
Part I
In this example, we are using try with resources,
so the client won’t need to be closed, as it will be
done automatically. On the other hand, the
response is only closed in both methods using the
readResponse method below.

Winter 2021
Customer Rest
Part II

On the right are the POST and PUT requests and


on the bottom is the DELETE request. In all
instances, the responses are closed explicitly.

Winter 2021
Response Handler

Whenever a request is
executed, a response handler
may be used. In the example,
the status code is checked to
validate that the request was
successful and it will return
the result as a string if the
request if it was, or the failing
status code otherwise. Please
note that using a response
handler will help avoid having
to close the response
afterwards.

Winter 2021
Example Response Handler in Action

Winter 2021
Web Application Description Language

The Web Application Description Language is designed to provide a description/specification of an


HTTP-based web application.

This helps provide documentation for people who want to use the application or a means for tools
to generate code according to this specification.

Winter 2021
References

- Apache HTTP Client Overview


- Get Request
- Post Request
- Response Handlers
- Closing Connections
- More info on try with resources
- More info on the WADL
- Netbeans Code Generation with WADL Tutorial

Winter 2021

You might also like