[% cmd = 'curl -i -X OPTIONS -H \'Connection: close\' '_ curl_auth_string _'https://example.org:1443' _ uri; INCLUDE helpers/api_command.tt cmd=cmd level=level+3; request = 'OPTIONS /api/' _ id _ '/ HTTP/1.1'; response = 'HTTP/1.1 200 OK Allow: GET, HEAD, OPTIONS, POST Accept-Post: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/#rel-' _ id _ '"'; INCLUDE helpers/api_req_res.tt request=request response=response level=level+3; -%]
[% END -%] [% IF col.actions.grep('^GET$').size -%]
You cannot request the entire collection at once, but instead you can simply page through the results. The response provides prev and next links you can follow to get the next page. To define the page number and the rows per page to return, you can pass the parameters page and rows. Default values are page=1 and rows=10, if you do not provide them.
[% cmd = 'curl -i -X GET -H \'Connection: close\' '_ curl_auth_string _'\'https://example.org:1443/api/' _ id _ '/?page=1&rows=1\''; INCLUDE helpers/api_command.tt cmd=cmd level=level+3; props = get_props_plain() | indent(12); request = 'GET /api/' _ id _ '/?page=1&rows=1 HTTP/1.1'; response = 'HTTP/1.1 200 OK Content-Type: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/" { "_embedded" : { "ngcp:' _ id _ '" : [ { "_links" : { "collection" : { "href" : "/api/' _ id _ '/" }, "curies" : { "href" : "http://purl.org/sipwise/ngcp-api/#rel-{rel}", "name" : "ngcp", "templated" : true }, "profile" : { "href" : "http://purl.org/sipwise/ngcp-api/" }, "self" : { "href" : "/api/' _ id _ '/1" } }, ' _ props _ ' }, ] }, "_links" : { "curies" : { "href" : "http://purl.org/sipwise/ngcp-api/#rel-{rel}", "name" : "ngcp", "templated" : true }, "next" : { "href" : "/api/' _ id _ '/?page=2&rows=1" }, "ngcp:' _ id _ '" : [ { "href" : "/api/' _ id _ '/1" }, ], "profile" : { "href" : "http://purl.org/sipwise/ngcp-api/" }, "self" : { "href" : "/api/' _ id _ '/?page=1&rows=1" } }, "total_count" : 100 }'; INCLUDE helpers/api_req_res.tt request=request response=response level=level+3; -%] [% END -%] [% IF col.item_actions.grep('^GET$').size -%]
[%
cmd = 'curl -i -X GET -H \'Connection: close\' '_ curl_auth_string _'\'https://example.org:1443/api/' _ id _ '/1\'';
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
props = get_props_plain() | indent(3);
request =
'GET /api/' _ id _ '/1 HTTP/1.1';
response =
'HTTP/1.1 200 OK
Content-Type: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/"
Link: ; rel=collection
Link:
[% request_macro(http_request = 'POST'); %]
[% END -%] [% IF col.item_actions.grep('^PUT$').size -%][% request_macro(http_request = 'PUT'); -%]
[% END -%] [% IF col.item_actions.grep('^PATCH$').size -%][% props = ''; rem = 0; rep = 0; FOREACH p IN col.fields; NEXT IF col.sample_orig && col.sample_orig.update && ( col.sample_orig.update != 'default' ) && ( !col.sample_orig.update.${p.name} ); type = p.types.0; IF type == 'null'; NEXT IF rem >= 1; op = "remove"; type = p.types.1; rem = rem + 1; ELSE; NEXT IF rep >= 1; op = "replace"; rep = rep + 1; END; IF type == "Number"; val = 5; ELSIF type == "String"; val = '"other"'; ELSIF type == "Boolean"; val = 'false'; ELSIF type == "Array"; val = '[]'; ELSE; val = '"missing"'; END; props = props _ '{ '; props = props _ '"op" : "' _ op _ '", "path" : "/' _ p.name _ '"'; UNLESS op == "remove"; props = props _ ', "value" : ' _ val; END; props = props _ ' }, '; LAST IF rep >= 1 && rem >= 1; END; props = props.substr(0, props.length - 2); cmd = 'curl -i -X PATCH -H \'Connection: close\' -H \'Content-Type: application/json-patch+json\' -H \'Prefer: return=minimal\' '_ curl_auth_string _'\'https://example.org:1443/api/' _ id _ '/2\' --data-binary \'[ ' _ props _ ' ]\''; INCLUDE helpers/api_command.tt cmd=cmd extended=1 level=level+3; %]
The PATCH method allows to operate on specific fields of an item. The path attribute can point to a normal property (e.g. /something) or to a specific element in an array (e.g. /something/0). Available op values are:
Removes the property pointed to by path. You can point to a normal property (e.g. /something) or to a specific element in an array (e.g. /something/0).
Replaces the value pointed to by path by the new value passed via value.
Adds a new property path by the new value passed via value.
Copies or moves (copy, then remove) the value from property defined by from to the propery defined by path.
[% cmd = 'curl -i -X DELETE -H \'Connection: close\' '_ curl_auth_string _'\'https://example.org:1443/api/' _ id _ '/1\''; INCLUDE helpers/api_command.tt cmd=cmd level=level+3; request = 'DELETE /api/' _ id _ '/1 HTTP/1.1'; response = 'HTTP/1.1 204 No Content'; INCLUDE helpers/api_req_res.tt request=request response=response level=level+3; -%]
[% END -%]