-
Notifications
You must be signed in to change notification settings - Fork 0
Sequence File
Sequence File
is a UTF-8 encoded text file with several lines
, it's name is a constant called sample.seq. A line
can be:
- an empty line,
- a commented line or
- a command line.
One command line has one command, the command can control the flow of requests we descibed in Request File
s.
Currentyly, there're 3 types of commands:
This command will launch a HTTP request using specified Request File
to target server and it will be considered as a sample in your document (its result will be present in your document).
//This is
// a
// comment
varName <[HTTP Code]< request-file-name [arg0 arg1 arg2 ... argN]
-
You can write any comments behind a
//
, the commented lines will be merged in to one string and be the description of the following sample in your final API document. -
varName
can be considered as a variable representing of the sample. As we mentioned above, if you analogize aRequest File
as a function, thevarName
would be the return value of the function. -
<[HTTP Code]<
is the operator of this command- You can specify an expected
HTTP Code
here to make sure the response is exaclty what you want. e.g:<201<
means you only accept201 CREATED
for this sample. - You can also omit the code,
<<
means any response code is accepted. - If the actual response code is not expected, the execution of
Sequence File
will be terminated.
- You can specify an expected
-
request-file-name
is the file name ofRequest File
we've prepared. -
The
[arg0 arg1 arg2 ... argN]
is the argument list for theRequest File
, using SPACE as the separator. See here for more.
- Use
PostUser.req
as the request.Abby
as the arguement to call to target server and no matter what the response code is, the response will be always saved to a variablea
, and the sample's description isAdd a user called Abby
//Add a user called Abby
a << PostUser.req Abby
- Use
PutUser.req
as the request. UseAbby Moore
, the former example's response's ETag header and id in body as the arguements to call to target server and if the response code is200
, the response will be saved to variableb
b <200< PutUser.req `Abby Moore` $a:ETag $a.id
This command is quite similar with Sample Command
, the only difference is that this command is commonly used to get some values for reference in subsequent commands, and will not be considered as a sample and appeared in final API document.
varName =[HTTP Code]= Request File-path [arg0 arg1 arg2 ... argN]
This command is totally as same as Sample Command
except the operator. ==
means accept any response and =304=
means only accpet 304 Not Modified
status code of response.
See examples in Sample Command
for reference.
This command will save the content of the request and the response to a text file. The content here includes HTTP status line, headers and body.
This command is usually used for troubleshooting since you can see the detail of the request and the response, it will not affect logic and result of the execution flow.
varName >> snapshot-file-name
-
varName
is a previously defined variable name in aRequest Command
or aSample Command
-
>>
is the operator of this command, which means write to a file. -
snapshot-file-name
is the name of the file you wanna to save to, the file will be saved inSample Package
Assume a request file get.req
like this, which accepts 2 args:
GET /foo{{{0}}}}
> Accept: {{{1}}}
And following commands in Sequence File
:
a <200< get.req `?price=lt 2.00` application/json
a >> result.txt
If you launch the tool, you'll get a file result.txt
in Sample Package
with following content:
GET /foo?price=lt 2.00
> Accept: application/json
HTTP/1.1 200 OK
< ETag: W/"3138717599:fcac158ad5062c1afb0ba55d45738767"
< Content-Type: application/json
< Content-Length: 1982
< Server: Jetty(8.1.7.v20120910)
< Content-Length: 170
{
"count":1,
"items":[
{
"url":"/shopping-cart/1",
"product":"2ZY48XPZ",
"quantity":1,
"name":"New socks",
"price":1.25
}
]
}
There're 3 types of argument:
-
string
-
Any string without SPACES can be directly considered as a string argument. e.g:
foo
,foo-123_bar
-
If the argument needs to have some SPACES, you need to embrace the string using a pair of
" "
e.g:" foo bar "
-
If the string itself contains
"
, use\"
to escape. e.g:I'm a \"nerd\"
-
ref of header value
Like variable in PHP, a $
and a defined varName
can be a reference of some previous defined variable in Request Command
or Sample Command
You can use a :
to access the header of the response which the variable represents.
e.g: $a:Etag
, $b:Content-Type
, $c:Content-Length
3. ref of body value
You can use a .
to access body of the response which the variable represents.
Here's an assumption that the response body must be JSON format, so you can access the body's element using .
for nested fields and []
for array fields.
Note that currently we only support access to the primitive element in JSON object.(string, number and boolean)
e.g: If the var foo
representing a response like this:
HTTP 200 OK
< Content-Type: application/json
< Content-Length: 170
{
"count": 1,
"items": [
{
"url": "/shopping-cart/1",
"product":"2ZY48XPZ",
"quantity": 1,
"name": "New socks",
"price": 1.25
} ]
}
Then,
$foo:Content-Type
= application/json
;
$foo.count
= 1
;
$foo.items[0].url
= /shopping-cart/1
;
$foo.items
and $foo
is not supported.