Tutorial 2 - The Rest Client: SOEN 487 - Web Services and Applications By: Nicholas Nagy
Tutorial 2 - The Rest Client: SOEN 487 - Web Services and Applications By: Nicholas Nagy
Rest Client
Winter 2021
Instructions to Follow Along
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
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
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
Winter 2021