top of page

Working with REST project

Updated: Jan 3, 2021

To understand what is Rest and creating new Rest project, refer the link.

We are taking a public API "deck of cards" to work on today. So let's create a new project by entering the following URL,

Create the rest project and create new test case from the request as mentioned in the previous blog

Understanding REST Parameters:

Before diving into the nuances of functionalities of this REST API, let see the style/parameters used in REST requests,






Let's explore more on the parameters by trying out few scenarios in "deck of cards" API.

Scenario 1: A Brand New Deck

A Deck has 52 cards, and by passing the following request, you can get a new deck with 52 cards created/generated in the response.

Simply paste the rest of the URI "/api/deck/new/" in resource tab and click play button. We can see the response with 52 cards generated in a deck.

Scenario 2: Shuffle the Cards

This following URI will help you to create a new deck and shuffle.

in the end if you see, "deck_count" is the parameter passed, to denote the number of decks to be created.

for example, if we pass deck_count as 1, we get deck of 52 cards with unique deck_id in response, same way, if we pass deck_count as 2, we get deck of 104 cards with unique deck_id in response.

Here, we are using the QUERY parameter to pass the deck_count.

Let's see how to do this in Soap UI,

Before passing the parameters, the Resource and Parameters tab will be empty.

Let's add rest of the URI path to create a new deck inside Resource tab and Click Parameters tab.

Enter "deck_count" as Name and its value, you can see now that the parameter is reflected in request tab with default style as QUERY. So the query parameter is used to pass the value in request URI.

Now we could see the response is displayed as expected as 52 remaining cards for deck_count = 1 with a unique "deck_id".

For "deck_count = 2", the remaining cards are 104 as expected.

Scenario 3: Draw a Card

This scenario helps us to draw a card or cards from the already created deck. A deck will be identified by its deck_id.<<deck_id>>/draw/?count=2

The count parameters defines how many cards should be drawn from the deck. Here we have to replace the <<deck_id>> with valid id in order to identify from which deck the card is drawn.

Let's see how to do this in SOAP UI,

Here we use TEMPLATE style to parameterize resource variable, i.e. deck_id

In this scenario, we are passing the deck_id from previously generated response. In our first Scenario, the deck_id we got in the response was "deck_id": "3my740t3a8rm".

We are passing the same value in this scenario as well to draw 2 cards (count =2 using QUERY parameter style) from the same deck.

In resource tab, we have specified deck_id as "{deck_id}" to make it a parameter, and selected "TEMPLATE" as style, and mentioned the value. Now run by clicking green play button, we could see details of two cards with code KS (king spade) and 5H (5 Hearts) are drawn from the mentioned deck.

If you observe the above screenshot, we have mentioned "deck_count" as PLAIN style, because we don't want that parameter to be used in this URI.

Now when we check the Raw tab the value is passed in place of deck_id.

Scenario 4: Discarding the card

A pile is used to move the card for example discard, move between players etc. We can specify the pile name to decide what to do with the cards.<<deck_id>>/pile/<<pile_name>>/add/?cards=code1,code2

Here, we are going to discard the cards we have created in previous requests. So we are going to send the following URL as the request,{deck_id}/pile/Discard/add/?cards=KS 

Here we are passing the deck_id we created before, and could see the card is discarded.

48 views0 comments

Recent Posts

See All

Smallest String With A Given Numeric Value

The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.


bottom of page