I was trying to create an API mock using apiary.io. A section of my current API blueprint looks like follows.
+ Request (application/json)
{
"key": "secret",
}
+ Response 200 (application/json)
{
"decision_type" : 1,
}
+ Response 202 (application/json)
{
"decision_type" : 2,
}
+ Response 203 (application/json)
{
"decision_type" : 3,
}
According to the API documentation provided to me, the ideal case should be such that the response status returned in all the three cases should be 200. But since apiary uses status codes to differentiate between the responses, I am forced to use 202 and 203 status codes. Is there any way by which I could avoid this?
I thought of a functionality by which it would give different responses based on different parameters. But it seems like this functionality is still being implemented (Apiary.io - multiple responses (200) with different parameters).
Is there a way to denote the blueprint like the following?
+ Response 200 (application/json) type=1
{
"decision_type" : 1,
}
+ Response 200 (application/json) type=2
{
"decision_type" : 2,
}
+ Response 200 (application/json) type=3
{
"decision_type" : 3,
}
And this type can be accessed as a header during REST calls.
I will be forced to turn down apiary and move to other applications to generate a mock which would mean a great deal of work as my API is really BIG.
API mock will always give your the first response in your document. If you just want to use it for mock you try something thing like this:
## Get Decision type 1 [/?type=1]
### decision type [GET]
+ Response 200 (application/json)
{
"decision_type" : 1,
}
## Get Decision type 2 [/?type=2]
### decision type [GET]
+ Response 200 (application/json)
{
"decision_type" : 2,
}
## Get Decision type 3 [/?type=3]
### decision type [GET]
+ Response 200 (application/json)
{
"decision_type" : 3,
}
Related
I want to use while controller to keep sending GET HTTP Request and only proceed to next POST HTTP Request when the GET response "model_name": "Model-Test-20220221-0001"
POST HTTP Request - paramter model_name = Model-Test-${variable}-${counter}
While Controller
GET HTTP Request. sample GET response at below
Json Extractor
POST HTTP Request only when While Controller found the exact model_name.
JSON Extractor:
Names of created variable: modelname
Json path expressions: I have tried this but failed
$..valid_model_list[?(#.model_name = ${Model-Test-${variable}-${counter}})]
This is sample HTTP Request response:
{
"message": "success",
"valid_model_list": [
{
"meta_data": {
"corpus_list": [
"test1"
],
"id": "0c36effa244b4f6596d10f9e675303e1",
"sample_rate": 16000,
"split_ratio": {
"test": 40,
"train": 60
},
"model_name": "Model-Test-20220221-0001",
"status": "ok"
},
{
"meta_data": {
"corpus_list": [
"test1"
],
"id": "0c36effa244b4f6596d10f9e675303e1",
"sample_rate": 16000,
"split_ratio": {
"test": 40,
"train": 60
},
"model_name": "Model-Test-20220221-0002",
"status": "ok"
}
}
]
}
}
We're "unsure" as well as we don't know what you're trying to achieve.
JSON Extractor can extract values from the response, it's not possible to use it to extract values from the request, moreover you should "know" what you're sending in the request and extracting values from the response is the essential part of the correlation process
If you're looking for a JSONPath expression extracting the model_name attribute value you're supposed to provide full JSON. There is a Deep Scan operator so you should be able to use something like:
$..model_name
but if there are more than 1 matches you might need to limit the output with Filter Operators
More information:
JsonPath Getting Started
API Testing With JMeter and the JSON Extractor
I have a post data request as the following,
{
"doctorId":1,
"userId":29,
"sampleConditions":[
{
"conditionId":"14",
"conditionName":"Acne",
"conditionDate":"2017-01-31"
}
],
"labOrder":{
"testId" : [1,2,3]
}
}
what happens, if the client gives the incorrect key
"sampleConditionss":[
{
"conditionId":"14",
"conditionName":"Acne",
"conditionDate":"2017-01-31"
}
],
Instead of giving sampleConditions, the client have sent the request as sampleConditionss.
How can i handle the request,
When you are using springs the spring framework will return 400 and you need not do anything here
I'm using swashbuckle to document my web api project and I cannot add multiple responses for precondition failed cases, swagger only shows the last one.
/// <response code="200">OK</response>
/// <response code="401">Unauthorized</response>
/// <response code="400">BadRequest</response>
/// <response code="412">ErrorCode = 1... </response>
/// <response code="412">ErrorCode = 2... </response>
/// <response code="412">ErrorCode = 3... </response>
Swashbuckle generates something like:
{
...
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "BadRequest"
},
"401": {
"description": "Unauthorized"
},
"412": {
"description": "ErrorCode = 3..."
}
}
...
}
Where I would like to see:
{
...
"412": {
"description": "ErrorCode = 1..."
},
"412": {
"description": "ErrorCode = 2..."
},
"412": {
"description": "ErrorCode = 3..."
}
}
Any thoughts about it?
Thanks in advance
What you are trying to achieve is not possible with Swashbuckle because it is not compliant with the Open API specification (aka Swagger). The responses object contains a list of possible responses. Each response has a name and a response object. The name can be default or a HTTP status code. According to the spec of a responses object there can be only one response object per status code:
Any HTTP status code can be used as the property name (one property per HTTP status code). Describes the expected response for that HTTP status code.
That being said, I doubt whether it is correct to add additional error codes to a 412 response. A conditional request might not reach your server in case a proxy server already knows the conditions won't be matched.
I've been trying to use the batch endpoint of MailChimp API (version 3.0) to subscribe new users to a list, but can't make it work.
Here is the request:
POST /3.0/batches
{
"operations": [
{
"method" : "POST",
"path" : "lists/c852ce5c86/members",
"body": "{\"email_address\":\"email#domain.tld\", \"status\":\"subscribed\"}"
}
]
}
The request seems ok cause I get a 200 response:
{
"id": "49abca6ef3",
"status": "finished",
"total_operations": 1,
"finished_operations": 1,
"errored_operations": 1,
"submitted_at": "2015-09-21T18:11:16+00:00",
"completed_at": "2015-09-21T18:11:23+00:00",
"response_body_url": "https://mailchimp-api-batch.s3.amazonaws.com/49abca6ef3-response.tar.gz?..."
}
However, as you can see, the only operation in my batch is errored.
Here is the response_body_url for this operation:
[{
"status_code":400,
"operation_id":null,
"response":"{
\"type\":\"http://kb.mailchimp.com/api/error-docs/400-invalid-resource\",
\"title\":\"Invalid Resource\",
\"status\":400,
\"detail\":\"The resource submitted could not be validated. For field-specific details, see the 'errors' array.\",
\"instance\":\"\",
\"errors\":[{
\"field\":\"\",
\"message\":\"Schema describes object, NULL found instead\"
}]
}"
}]
which is not very helpful :(
Note that if I directly hit POST lists/c852ce5c86/members with {"email_address":"email#domain.tld", "status":"subscribed"} payload, it's working properly.
That was actually a bug in the mailchimp API. After reaching them they quickly fixed it.
I have problem with the ESPN API:
I have an API key, and sent a query to the address http://api.espn.com/v1/sports/news/1581816?region=GB, which included my API key in the parameters.
I received 403 forbidden response: with this JSON
{
"status": "error",
"code": 403,
"message" : "Account Inactive"
}
I am looking at http://developer.espn.com/docs/headlines#using-the-api and at the last line it says that i can make a GET request to this url and it should work, but it doesn't.
How can I receive a valid response from the ESPN servers?
I just test it and it works fine. That means your key is invalid, or you are not including it. Replace below and it will work.
http://api.espn.com/v1/sports/news/1581816?region=GB&apikey=<yourKey>
--
{
timestamp: "2013-10-13T15:33:49Z",
resultsOffset: 0,
status: "success",
resultsLimit: 10,
resultsCount: 1,
headlines: [
{ ... }
]
}