Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Spring 5.0 By Example

You're reading from   Spring 5.0 By Example Grasp the fundamentals of Spring 5.0 to build modern, robust, and scalable Java applications

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781788624398
Length 356 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
 de Oliveira de Oliveira
Author Profile Icon de Oliveira
de Oliveira
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
1. Journey to the Spring World FREE CHAPTER 2. Starting in the Spring World – the CMS Application 3. Persistence with Spring Data and Reactive Fashion 4. Kotlin Basics and Spring Data Redis 5. Reactive Web Clients 6. Playing with Server-Sent Events 7. Airline Ticket System 8. Circuit Breakers and Security 9. Putting It All Together 1. Other Books You May Enjoy Index

Testing APIs


Our container is running. Now, we can try to call the APIs to check the behaviors. In this part, we will use the curl command line. The curl allows us to call APIs by the command line on Linux. Also, we will use jq to make the JSON readable on the command line, if you do not have these, look at the Tip Box to install these tools.

Let's call our create API, remember to create we can use the POST method in the base path of API. Then type the following command:

curl -H "Content-Type: application/json" -X POST -d '{"hashTag":"java","queue":"java"}' \
 http://localhost:9090/api/tracked-hash-tag

There are interesting things here. The -H argument instructs curl to put it in the request headers and -d indicates the request body. Moreover, finally, we have the server address.

We have created the new tracked-hash-tag. Let's check our GET API to obtain this data:

curl 'http://localhost:9090/api/tracked-hash-tag' | jq '.'

Awesome, we called the curl tool and printed the JSON value with the jq...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images