DEV Community

Discussion on: Testing your API with REST Client

Collapse
 
techwatching profile image
Alexandre Nédélec

Yes you can, you just have to call the first request, then the second request.
You can find below an example. I tested it, it works fine.

### First request
# @name myRequest
POST https://jsonplaceholder.typicode.com/posts
Content-Type: application/json

{
    "userId": 1,
    "title": "TEST 18",
    "body": "TEST body 18"
}

### Second request using response in body 
POST https://jsonplaceholder.typicode.com/posts
Content-Type: application/json

{
    "userId": 1,
    "title": "TEST ",
    "body": "TEST body {{myRequest.response.body.id}}"
}

### Second request using a variable 
@test2 = {{myRequest.response.body.id}}
POST https://jsonplaceholder.typicode.com/posts
Content-Type: application/json

{
    "userId": 1,
    "title": "TEST ",
    "body": "TEST body {{test2}}"
}