Documenting query parameters with API Blueprint - apiblueprint

I'm trying to document a query parameter in API Blueprint, but I'm not entirely sure if I have done it correctly. The resource looks like this:
DELETE http://baasar.apiary-mock.com/user/{appId}/{userId}
That request would deactivate the user while the following would delete the user object:
DELETE http://baasar.apiary-mock.com/user/{appId}/{userId}?force=true
This is the Blueprint markdown I have for this:
## User [/user/{appId}/{userId}]
Handle user objects
+ Parameters
+ appId (required, number, `1`) ... Application ID (`appId`)
+ userId (required, number, `1`) ... Numeric `userId` of the User object to manage
### Remove an User [DELETE]
+ Parameters
+ force (optional, boolean, `false`) ... Set to `true` to remove instead of deactivate
+ Response 204
However, when rendering this with Apiary I only see force in the list of parameters, but it is now shown in the example URL. Is that just me misunderstanding the GUI or should query parameters be documented in another way?

Your blueprint is perfectly fine, the problem is that the current Apiary documentation does not handle URI parameters correctly.
Could you please try the new documentation out? It should handle URI parameters properly.
Edit
The correct URI Template should be:
http://baasar.apiary-mock.com/user/{appId}/{userId}{?force}

My curl request:
curl -k -u username:password https://api.techie8.io/api/1.0/bits?bit_type=1
Apiary blueprint:
## Bits Collection [/bits?bit_type={bit_type}]
### List Latest bits [GET]
List all bits recently inserted into database.
+ Parameters
+ bit_type (number, optional, `1`) ... Type of bit to retrieve: 1: Bits, 2: Newsletter

Related

Can Jmeter LDAP Request or LDAP Extended Request populate a multi-valued attribute?

I am working on a Jmeter LDAP test plan and the test plan has to populate an attribute on the LDAP that is multi-valued.
When I do an LDAP search sampler, I noted that the value I get back is a string, with the values separated by ", ".
But, if I take the same comma-separated string and try to do an LDAP modify or add, using either an LDAP Request or LDAP Extended Request, I get an error.
So I am wondering if there is a way that the Jmeter LDAP Request or LDAP Extended Request can do that?
Thanks,
Jim
EDIT: When I try to use an Extended LDAP Request modification test/add with the attribute of "", I get this error in the Jmeter GUI response:
When attempting to modify entry cn=xxx... to replace the set of values for attribute lastlogindate, value "20181023085627-04, 20181024063205-04" was found to be invalid according to the associated syntax: The provided value "20181023085627-04, 20181024063205-04" is not a valid generalized time value because it contains an invalid character '-' at position 14
The strange part is that even though I have Jmeter to log at debug level, I don't see any detail on the error in the Jmeter.log, but/so I am guessing that that error message is coming from the Jmeter client itself. I noticed that the message says:
to replace the set of values
so it seems like it recognizes that I am trying to modify/replace a multi-value, but it doesn't seem to like the syntax of the replacement values string(s).
Does anyone know what the correct format SHOULD be?
I found the answer to my own question, or at least "A" answer: It appears that I can use an Extended LDAP request, and add the same attribute in that request, multiple times. So for example, if I am populating an attribute named "foo" the Extended LDAP request would have the following:
attribute value opcode
foo 12345 add
foo 12346 add
etc.
I think I also need to do a replace with no value, to empty the attribute, before all the adds.

Have Dynamical values for my parameters in the Request payload (POST x-www-form-urlencoded)

Is there a way (and does it make sense even) to have dynamical values for my request parameters (in my case POST application/x-www-form-urlencoded that has two parameters username and password) which can be altered based on some function or a returned value from the server from a previous request?
The motivation being that i have a register-new-user request which i run from time to time off apiary.io and unless i manually change the example value for the username i get a "use already exists" response instead of 201 i want (since this request was already run with the username in the example).
What i'd like to have instead is a value in the API documentation that will change on each execution of the API call (either using some random number there, or to be able to have it take a value returned from a previous request).
Is there anything you can suggest to solve my "user already exists" response for register-new-user API call?
Here is my current API documentation (the relevant part):
## Registration [/users.json]
The `/users.json` resource handles registration of new user
### Register a New Patient [POST]
Register a new patient action sends email and password and registers
the new user in case it doesn't already exist
+ Request (application/x-www-form-urlencoded)
+ Attributes (Test User)
+ Body
user[email]=username#example.com&user[password]=123456
+ Response 201 (application/json)
{
"id":500
}
# Data Structures
## Test User (object)
+ "user[email]" (string): "username#example.com" - user email
+ "user[password]" (string): "123456" - user password
Thanks in advance
You can partially simulate this in the Apiary mock server by passing a header in your call, for example:
Prefer: status=200
See https://help.apiary.io/tools/mock-server/#multiple-responses
In general the mock server is not yet flexible and programmable enough to fully do what you describe, for example conditionals, dynamic variables or random responses.
We are working on enhancing this. If you'd like you may comment here on your requirements:
https://github.com/apiaryio/api-blueprint/issues/58
Feel free to also ping us in Apiary (in-app chat) or on support#apiary.io.
Thanks

ElasticSearch API POST/PUT DeDupe

I am looking to use the Elastic Search RESTful API to send data to my ES instance. Here is some sample data:
[{"subject":"matt","predicate":"likes","object":"coffee","label":"1_10"}]
[{"subject":"james","predicate":"likes","object":"water","label":"1_10"}]
[{"subject":"leo","predicate":"likes","object":"liquor","label":"1_10"}]
[{"subject":"matt","predicate":"likes","object":"coffee","label":"1_10"}]
[{"subject":"matt","predicate":"likes","object":"coffee","label":"1_10"}]
My post call looks like:
"http://" + url + "/something/quads/
With the JSON payload.
I was looking at a put call and was trying the following:
"http://" + url + "/something/quads/_create
from this documentation: https://www.elastic.co/guide/en/elasticsearch/guide/current/create-doc.html
The problem is that it created the ID in ES as _create Is there something I am doing wrong?
If you use POST calls with URLs like /something/quads/ then ES will automatically generate IDs for your documents.
If, instead, you want to use PUT calls, you need to provide document IDs yourself in the URL /something/quads/123, /something/quads/456, etc.
In your second URL /something/quads/_create, you're missing the document ID. It should be /something/quads/123/_create. Check the docs you've linked to again and you'll see.
Also note that the difference between the two following commands
PUT /something/quads/123
PUT /something/quads/123/_create
is that the second will fail if a document with the ID 123 already exists. The first command, however, will always succeed and overwrite the document with ID 123 if one exists.

Is there any way to send empty optional query parameters?

I'm writing documentation for API, and got problem.
Here is link definition:
### Get hotels availability [GET /agent/v1/hotel/availability{?regions,hotels,from,to,limit,offset}]
Parameters:
+ Parameters
+ regions (required,string,`399,189`)
+ hotels (optional, string, `1844`)
+ from (optional, string, `2016-03-12`)
+ to (optional, string, `2016-03-19`)
+ limit (optional, number, `1`)
+ offset (optional, number, `0`)
When I'm trying to send request with empty hotels parameter for example, apiary uses 1844 instead of empty. If I'll try to example it to empty, hotels=hotels is sended.
Is there any way to send empty for optional parameter, or not send it at all?
Here is link with screenshot:
http://www.awesomescreenshot.com/image/1008356/09614be501945b0644fd84a06e311404
I'm not sure whether I understand your problem correctly. I tried to reproduce the behavior you described. I created a new API Project in Apiary and wrote following API Blueprint:
FORMAT: 1A
# Hotels API
# Group Hotels
## Hotels [/agent/v1/hotel/availability{?regions,hotels,from,to,limit,offset}]
+ Parameters
+ regions (required,string,`399,189`)
+ hotels (optional, string, `1844`)
+ from (optional, string, `2016-03-12`)
+ to (optional, string, `2016-03-19`)
+ limit (optional, number, `1`)
+ offset (optional, number, `0`)
### Get hotels availability [GET]
+ Response 200 (application/json)
{"hello":"world"}
Then I opened console pane in the generated interactive documentation and tried to edit URL parameters:
The URL at the top is changing correctly. I made some requests with the Console and the Traffic Inspector page seems to confirm that correct parameters has been sent:
I think you'll have to refine your question and provide more information. Also, I believe this is fairly Apiary-specific topic and it may make more sense to contact Apiary Support at support#apiary.io instead. If e-mail isn't your thing, there's also an interactive chat:
Disclaimer: At the time of writing the answer I work for Apiary.

How to document POST parameters with Apiary?

I've written a small web service that was designed to be "curl-able", so it relies on application/x-www-form-urlencoded parameters in POST requests, e.g.:
curl http://api.example.com/ -d param1=foo -d param2=bar
I would like to document this service using Apiary, but I've been unable to figure out a way to provide structured documentation for these parameters. I can provide an example request like this...
+ Request (application/x-www-form-urlencoded)
param1=foo&param2=bar
...but this doesn't allow me to provide documentation on the
individual parameters (and does not lend itself well to testing in the
apiary console, since it is unable to provide input fields for the
various parameters).
I've read through the api blueprint specification a few
times and I've been unable to find a good solution. Is there any way
to provide structured documentation for these parameters?
You can use Attributes for this type description.
FORMAT: 1A
HOST: http://api.example.com/
# Test attributes 1
## Create post [/]
### Create a Post [POST]
+ Attributes
+ param1: foo (string) - Foo param
+ param2: bar (string) - Bar param
+ Request (application/x-www-form-urlencoded)
+ Response 201

Resources