简体   繁体   English

Postman 模拟服务器,用于具有动态请求标头/正文的请求

[英]Postman mock server for requests with dynamic request headers/body

I am using Postman mock server to create a mock endpoint where I need the response of the request to contain the request parameter as well as few other key values.我正在使用 Postman 模拟服务器来创建一个模拟端点,我需要在请求的响应中包含请求参数以及一些其他键值。

For example if my endpoint is /test?id=123 then i need the response as例如,如果我的端点是 /test?id=123 那么我需要响应为

    {
        "id":"123",
        "name":"anyRandomName"
    } 

Similarly, when I hit /test?id=234 then the response should be同样,当我点击 /test?id=234 时,响应应该是

{
    "id":"234",
    "name":"anyRandomName2"
}

One way to achieve this is by making 2 endpoints with specific query parameters, in this example /test?id=123 and /test?id=234 .实现此目的的一种方法是使用特定查询参数创建 2 个端点,在本例中为/test?id=123/test?id=234 But i am looking for a way where i can read the request parameter just like {{$id}} or something like this.但我正在寻找一种方法,我可以像{{$id}}或类似的东西读取请求参数。 Postman do provide keywords like {{$randomAlphaNumeric}} which returns random strings but this will change in every hit. Postman 确实提供了像{{$randomAlphaNumeric}}这样的关键字,它返回随机字符串,但每次点击都会改变。

You can pass the example name in headers while making a call to the mock API with key "x-mock-response-name".您可以在使用键“x-mock-response-name”调用模拟 API 时在标题中传递示例名称。 this will return the example set with that name.这将返回具有该名称的示例集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM