Resources usually have multiple get methods. Get a singular or get many by query params. How is this represented in blueprint? I can do it using two resources, but that in my opinion is not correct as its the same resource.
Related to this question How does one add PUT to the resource given the uri is defined at the resource level.
Ideally this is how i think things should be written but the editor doesn't like it. I have found in docs where the HTTP_ACTION and URI can be put together, but the editor seems to want the URI at the resource level.
# Storefronts
## Read [GET /v1/storefronts{?query_params...}]
+ Parameter
query_params ...
+ Request Matching Storefronts (application/json)
+ Response 200 (application/json)
## Read [GET /v1/storefronts/{id}]
+ Parameter
+ id (string) ... id for record to return
+ Request (application/json)
+ Response 200 (application/json)
## UPDATE [PUT /v1/storefronts/{id}]
+ Parameter
+ id (string) ... id for record to update
+ Request (application/json)
+ Response 200 (application/json)
Technically you have 2 resources: one representing a single Storefront with an identity (typically supporting GET, PUT, DELETE, PATCH) and one representing a collection of Storefronts (typically supporting GET, POST). Here's how you would represent this in API Blueprint:
# Storefront [/v1/storefronts/{id}]
## Retreive a Single Storefront [GET]
## Update a Storefront [PUT]
## Delete a Storefront [DELETE]
# Storefronts Collection [/v1/storefronts]
## List Storefronts [GET]
## Create a New Storefront [POST]
Related
I use JMeter in our product performance testing now.
I have a performace test scenario below:
Exract 1000 unique IDs from a request A.
Add the 1000 unique IDs to next request B as "form parameters". check the request B response time.
The request B is like:
Method: Post
URL: http://www.aaa.com/abc/def
Form parameters:
para1 : value1
para2 : value2
ID : ID1
ID : ID2
ID : ID3
......
ID : ID1000
I know this request isn't a Canonical usage of http request. but it is used in our product for years.
Now I get the 1000 unique IDs from request A with the help of "regular expression extractor",
My question is:
how to pass the variables to request B, and set the 1000 IDs as "form parameters" of request B?
Add JSR223 PreProcessor as a child of the HTTP Request sampler where you need to add 1000 parameters
Put the following code into "Script" area:
def data = new org.apache.jmeter.config.Arguments()
1.upto(vars.get('ID_matchNr') as int, index -> {
def parameter = new org.apache.jmeter.protocol.http.util.HTTPArgument('ID', vars.get('ID_' + index))
data.addArgument(parameter)
})
sampler.setArguments(data)
That's it, the JSR223 PreProcessor will read all the JMeter Variables which start with ID_1 and ending with ID_XXXX and add a corresponding parameter to the HTTP Request sampler
More information on Groovy scripting in JMeter context: Apache Groovy - Why and How You Should Use It
I have a script include two HTTP request
1 The first request is User Authentication。include userId.....
2: the second request also includes userId.
The two parameters are consistent。
How to get the first userID from the first request and transfer to second request same userId?
I want to get userID from the first request, not from the response, response body does not include userId, transfer the same userId to the second request.
Here is the first request body:
[
{"productId":"5551",
"userId":"${__RandomString(32,44e00d674dee4ff7a2d4f0081991b6d40Bs9Hc)}",
"service":"200008",
"app_system":"7.1.1",
"equipmentId":"866935038314977",
"app_devicetype":"vivo X20A",
"app_platform":"Android",
"app_version":"3.1.3",
"market":"icash_main"}
]
Use Extractors for the co-relating your requests and responses.
First, you need to extract the userID from the response of your 1st requests.
To do this, choose an extractor (Use JSON Extractor if your requests return the JSON response) and add to your 1st request.
Second, After getting the value of userId through a variable using the extractor, you can use it in your subsequent requests.
Edit:
As you want to use the same userId in both requests, use User Defined Variables in your test plan and add a variable userID in it like this:
In your request body use the variable of userId like this:
{"productId":"5551",
"userId":"${userId}",
"service":"200008",
"app_system":"7.1.1",
"equipmentId":"866935038314977",
"app_devicetype":"vivo X20A",
"app_platform":"Android",
"app_version":"3.1.3",
"market":"icash_main"}
Here is the requests body of the two requests which are using the same userId
Body of the Request 1:
Body of the Request 2:
I have a collection response which gives back an array of user objects and want to have different values for the user attributes without to create multiple user objects. Is there a way to do this?
# Group Users
## Users Collection [/api/v1/users]
### View Users [GET]
+ Request (application/vnd.api+json)
+ Headers
Accept: application/vnd.api+json
Authorization: Bearer JWT
+ Response 200 (application/vnd.api+json)
+ Attributes
+ meta (UsersMetaData)
+ data (array[User, User])
+ links (UserLinks)
# Data Structures
## User
+ type: users (string, required, fixed)
+ id: 1 (number, required)
+ attributes (UserAttributes, required)
## UserAttributes
+ email: test#test.com (string)
+ confirmed: false (boolean)
+ first_name: Melanie (string)
I don't want to create multiple user data structures to avoid an overload. But maybe there is a way to create sample arrays or something to do this in an easy way?
Edit: I just found out this way, in case someone has the same or similar question:
+ Response 200 (application/vnd.api+json)
+ Attributes
+ data (array)
+ (User)
+ attributes (UserAttributes)
+ email: `another#mail.com` (string)
+ confirmed: true (boolean)
+ (User)
+ attributes (UserAttributes)
+ first_name: Darth Vader
This way it is possible to rewrite just the attributes for each object without the need to create new ones.
How can I ommit property from defined MSON? I have defined one simple entity (object) using MSON:
# Data Structures
## Article (object)
Represents an article
## Properties
+ id: 1 (number, optional)
+ name: My first article (string)
## Articles [/articles]
### Get all articles [GET]
Get all articles available on this website.
+ Response 200 (application/json)
+ Attributes (array[Article])
### Create an article [POST]
Create new article.
+ Request (application/json)
+ Attributes (Article)
I'm using Article object in several api endpoints. The problem is that I don't want id to be specified when posting new article so I want to omit it in the documentation for POST method. Is it possible to include Article entity in all endpoints and say what fields I want to omit?
There is no actually way how to do it.
You have two options:
declare id with attribute nullable
Declare Article without id and later inherit from Article and attach id.
# Data Structures
## Article (object)
+ name: My first article (string)
## ArticleInstance (Article)
+ id (number)
## Articles [/articles]
### Get all articles [GET]
Get all articles available on this website.
+ Response 200 (application/json)
+ Attributes (array[Article])
### Create an article [POST]
Create new article.
+ Request (application/json)
+ Attributes (Article)
I have an API contract defined in Apiary and I'm using the Resource model syntax to enable reuse of payloads.
The documentation rendered by Apiary only shows the model name though (eg Response 200 returns a [Foo][]) - without any further details on what Foo is, or any link to view the attributes in the Foo model.
Given a model, how do I see what its attributes are in the rendered documentation?
update
The relevant part of the contract is below:
### Manipulating a specific Organisation [/organisations/{id}]
Operations to retrieve and update a specific Organisation.
+ Parameters
+ id (required, guid, `F339ADA5-E836-40FE-8E90-BEF06892762E`) ... The guid Organisation `id`.
+ Model (application/json)
+ Headers
Link : <http://foobar.com/organisations/F339ADA5-E836-40FE-8E90-BEF06892762E>;rel="self"
+ Body
{
"id" : "F339ADA5-E836-40FE-8E90-BEF06892762E",
"name" : "joe's gardening supplies"
}
### Retrieve an Organisation [GET]
+ Response 200
[Organisation][]
### Update an Organisation [PATCH]
+ Request
[Organisation][]
+ Response 204
Unless you provide an example, it's just guessing, but my first guess would be wrong level of indentation. How example blueprint could look like:
FORMAT: 1A
HOST: http://www.google.com
# Model Example
Notes API is a *short texts saving* service similar to its physical paper presence on your table.
# Group Notes
Notes related resources of the **Notes API**
## Note [/notes/{id}]
A single Note object with all its details
+ Parameters
+ id (required, number, `1`) ... Numeric `id` of the Note to perform action with. Has example value.
+ Model
+ Header
X-My-Header: The Value
+ Body
{ "id": 2, "title": "Pick-up posters from post-office" }
### Retrieve a Note [GET]
+ Response 200 (application/json)
[Note][]
### Remove a Note [DELETE]
+ Response 204
Code above results in this documentation, where model is correctly incorporated on places where it's referenced (and where such reference is supported - i.e. definition of payload).
Sometimes it's helpful to read the raw version of Apiary's docs on GitHub, because it's easier to spot the right, exact format that way.
ok, from comparing the two examples I've worked it out.
in my contract the model reference
[Organisation][]
was indented two tabs instead of one. :S
that's a really easy mistake to make - would be helpful if Apiary flagged the incorrect indentation level for a model reference.