3

I need to reuse value which is generated for my previous request.

For example, at first request, I make a POST to the URL /api/products/{UUID} and get HTTP response with code 201 (Created) with an empty body.

And at second request I want to get that product by request GET /api/products/{UUID}, where UUID should be from the first request.

So, the question is how to store that UUID between requests and reuse it?

igrybkov
  • 43
  • 4

4 Answers4

3

You can use the Request Sent Dynamic values https://paw.cloud/extensions?extension_type=dynamic_value&q=request+send these will get the value used last time you sent a requst for a given request.

In your case you will want to combine the URLSentValue with the RegExMatch (https://paw.cloud/extensions/RegExMatch) to first get the url as it was last sent for a request and then extract the UUID from the url.

e.g

REQUEST A) Request With UUID REQUEST B) Request That uses other requests UUID

Matthaus Woolard
  • 2,310
  • 11
  • 13
0

The problem is in your first requests answer. Just dont return "[...] an empty body."

If you are talking about a REST design, you will return the UUID in the first request and the client will use it in his second call: GET /api/products/{UUID}

The basic idea behind REST is, that the server doesn't store any informations about previous requests and is "stateless".

I would also adjust your first query. In general the server should generate the UUID and return it (maybe you have reasons to break that, then please excuse me). Your server has (at least sometimes) a better random generator and you can avoid conflicts. So you would usually design it like this:

CLIENT: POST /api/products/ -> Server returns: 201 {product_id: UUID(1234...)}
Client: GET  /api/products/{UUID} -> Server returns: 200 {product_detail1: ..., product_detail2: ...}

If your client "loses" the informations and you want him to be later able to get his products, you would usually implement an API endpoint like this:

Client: GET  /api/products/ -> Server returns: 200 [{id:UUID(1234...), title:...}, {id:UUID(5678...),, title:...}]
chickahoona
  • 1,914
  • 14
  • 23
  • The question is about specific REST client (Paw), not about designing APIs. – igrybkov Oct 11 '16 at 21:21
  • Sorry, didn't complete the previous answer. However, there is no reason to generate UUID on server-side as it may be generated on the client and just validated on the server. And if API endpoint is not returning data, there is no reason to send UUID from request back to the client as it already should know it. – igrybkov Oct 11 '16 at 21:27
0

Given something like this, presuming the {UUID} is your replacement "variable": Original tag in URL

It is probably so simple it escaped you. All you need to do is create a text file, say UUID.txt:

UUID in text file

(with sample data say "12345678U910" as text in the file)

Then all you need to do is replace the {UUID} in the URL with a dynamic token for a file. Delete the {UUID} portion, then right click in the URL line where it was and select

Add Dynamic Value -> File -> File Content :

Add Dynamic Value - File Content

You will get a drag-n-drop reception widget:

File Drag-n-Drop Receiver Widget

Either press the "Choose File..." or drop the file into the receiver widget:

File Drag-n-Drop Receiver Widget with File

Don't worry that the dynamic variable token (blue thing in URL) doesn't change yet... Then click elsewhere to let the drop receiver go away and you will have exactly what you want, a variable you can use across URLs or anywhere else for that matter (header fields, form fields, body, etc):

enter image description here

Paw is a great tool that goes asymptotic to awesome when you explore the dynamic value capability. The most powerful yet I have found is the regular expression parsing that can parse raw reply HTML and capture anything you want for the next request... For example, if you UUID came from some user input and was ingested into the server, then returned in a html reply, you could capture that from the reply HTML and re-inject it to the URL, or any field or even add it to the cookies using the Dynamic Value capabilities of Paw.

Cerniuk
  • 14,220
  • 2
  • 29
  • 27
0

@chickahoona's answer touches on the more normal way of doing it, with the first request posting to an endpoint without a UUID and the server returning it. With that in place then you can use the RegExpMatch extension to extract the value from the servers's response and use it in subsequent requests.

Alternately, if you must generate the UUID on the client side, then again the RegExpMatch extension can help, simply choose the create request's url for the source and provide a regexp that will strip the UUID off the end of it, such as /([^/]+)$.

A third option I'll throw out to you, put the UUID in an environment variable and just have all of your requests reference it from there.

cabbey
  • 226
  • 3
  • 14