Parameter in a REST API


#1

In a restful API, I try to pass a parameter { zooId } in the URL like this:

@restful(subPath='/zoos/{zooId}/animals', paramsArg='spec')
    zoosToAnimals: function(zooId: string, spec: zoosToAnimalsSpec): json js server

In the js I have a function zoosToAnimals which get all animals in the zoo with the { zooId }

function zoosToAnimals(zooId, zoosToAnimalsSpec) {}

When I call the URL I have to pass the { zooId } in the body of the request.

In this exemple I just want to get the list off all animals of the zoo with the id (1)

url : /zoos/1/animals

{
        "zooId":"1",
	"spec": {
	}
}

Is it possible to get the { zooId } from the URL without putting it in the body of the request ??


POST/PUT call with Path Parameter and a Request Body
#2

The c3ShowType of Ann.Restful is mentioning that the url params feature is for GET requests:

but in addition types can create custom URLs using GET and REST-style argument extraction rather than POST requests.


#3

Ok when I try to use GET, I get the { zooId } and other parameters, but if I try to pass a parameter as an array of string I have some troubles.

I have a parameter name data which contains an array of string.

data=["id","name", ...]

url_1: /zoos/1/animals?data[]=“id”&data[]=“name”&"limit=1&offset=1&order=id
url_2: /zoos/1/animals?data=[“id”,“name”]&limit=1&offset=1&order=id
url_3: /zoos/1/animals?data=id,name&limit=1&offset=1&order=id

No spec, only params in url

@restful(subPath='/zoos/{zooId}/animals')
    zoosToAnimals: function(zooId: string, data: [string], limit: integer, offset: integer, order: string): json js server
function zoosToAnimals(zooId, data, limit, offset, order) {
return {
        zooId: zooId,
        data: data,
        limit: limit,
        offset: offset,
        order: order
    };
}

But at the end data is empty data=[] or null, is the reason why I try to pass all parameters in the body of the request.
So if we are using GET:
Is it possible to pass an array of string as parameter in the URL ?
Or can we pass this array of string in the body of the request ?


#4

@Charles arrays in query parameters are not supported yet. As a workaround I suggest having a comma-separated string parameter (i.e. data=v1,v2,v3) then when you receive the field split it by , to get your values.