parent
9587330201
commit
c799df3ebd
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/perl -w
|
||||||
|
use strict;
|
||||||
|
use Sipwise::Base;
|
||||||
|
use Data::Printer;
|
||||||
|
use NGCP::Panel::Form::BillingFee;
|
||||||
|
|
||||||
|
sub field_to_json {
|
||||||
|
my $name = shift;
|
||||||
|
|
||||||
|
given($name) {
|
||||||
|
when(/Float|Integer|Money|PosInteger|Minute|Hour|MonthDay|Year/) {
|
||||||
|
return "Number";
|
||||||
|
}
|
||||||
|
when(/Boolean/) {
|
||||||
|
return "Boolean";
|
||||||
|
}
|
||||||
|
when(/Repeatable/) {
|
||||||
|
return "Array";
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
return "String";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $form = NGCP::Panel::Form::BillingFee->new;
|
||||||
|
|
||||||
|
foreach my $f($form->fields) {
|
||||||
|
next if (
|
||||||
|
$f->type eq "Hidden" ||
|
||||||
|
$f->type eq "Button" ||
|
||||||
|
$f->type eq "Submit" ||
|
||||||
|
0);
|
||||||
|
my @types = ();
|
||||||
|
push @types, 'null' unless $f->required;
|
||||||
|
push @types, field_to_json($f->type);
|
||||||
|
|
||||||
|
print $f->name . " (" . join(', ', @types) . ")" . "\n";
|
||||||
|
}
|
@ -0,0 +1,431 @@
|
|||||||
|
<h[% level %] id="[% id %]">
|
||||||
|
[% IF uri -%]
|
||||||
|
<a href="[% uri %]" rel="collection">
|
||||||
|
[% END -%]
|
||||||
|
[% title %]
|
||||||
|
[% IF uri -%]
|
||||||
|
</a>
|
||||||
|
[% END -%]
|
||||||
|
</h[% level %]>
|
||||||
|
|
||||||
|
<h[% level + 1 %]>Description</h[% level + 1%]>
|
||||||
|
|
||||||
|
[% col.description %]
|
||||||
|
|
||||||
|
<h[% level + 1 %]>Properties</h[% level + 1%]>
|
||||||
|
|
||||||
|
<ul id="[% id %]-props">
|
||||||
|
[% FOREACH f IN col.fields -%]
|
||||||
|
<li><b>[% f.name %] </b>(<i>[% f.types.join(', ') %]</i>): [% f.description %]</li>
|
||||||
|
[% END -%]
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h[% level + 1 %]>Examples</h[% level + 1 %]>
|
||||||
|
<div class="examples">
|
||||||
|
|
||||||
|
<h[% level + 2 %]>Request available HTTP methods on the URI</h[% level + 2 %]>
|
||||||
|
<p>
|
||||||
|
[%
|
||||||
|
cmd = 'curl -i -X OPTIONS -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem https://example.org:1443/api/' _ id _ '/';
|
||||||
|
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;
|
||||||
|
-%]
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h[% level + 2 %]>Request the entire <i>[% id %]</i> collection</h[% level + 2 %]>
|
||||||
|
<p>
|
||||||
|
<p>
|
||||||
|
You cannot request the entire collection at once, but instead you can simply page through the results. The response provides <i>prev</i> and <i>next</i> 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 <i>page</i> and <i>rows</i>. Default values are <i>page=1</i> and <i>rows=10</i>, if you do not provide them.
|
||||||
|
</p>
|
||||||
|
[%
|
||||||
|
cmd = 'curl -i -X GET -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/?page=1&rows=2\'';
|
||||||
|
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
|
||||||
|
|
||||||
|
props = ' "id" : 1';
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
NEXT IF p.types.0 == 'null';
|
||||||
|
props = props _ ',
|
||||||
|
';
|
||||||
|
IF p.types.0 == "Number";
|
||||||
|
val = 4;
|
||||||
|
ELSIF p.types.0 == "String";
|
||||||
|
val = '"test"';
|
||||||
|
ELSIF p.types.0 == "Boolean";
|
||||||
|
val = 'true';
|
||||||
|
ELSIF p.types.0 == "Array";
|
||||||
|
val = '[]';
|
||||||
|
ELSE;
|
||||||
|
val = '"missing"';
|
||||||
|
END;
|
||||||
|
props = props _ ' "' _ p.name _ '" : ' _ val;
|
||||||
|
END;
|
||||||
|
props = props _ '
|
||||||
|
';
|
||||||
|
|
||||||
|
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;
|
||||||
|
-%]
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h[% level + 2 %]>Request a specific <i>[% id %]</i> item</h[% level + 2 %]>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
[%
|
||||||
|
cmd = 'curl -i -X GET -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/1\'';
|
||||||
|
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
|
||||||
|
|
||||||
|
props = ' "id" : 1';
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
NEXT IF p.types.0 == 'null';
|
||||||
|
props = props _ ',
|
||||||
|
';
|
||||||
|
IF p.types.0 == "Number";
|
||||||
|
val = 4;
|
||||||
|
ELSIF p.types.0 == "String";
|
||||||
|
val = '"test"';
|
||||||
|
ELSIF p.types.0 == "Boolean";
|
||||||
|
val = 'true';
|
||||||
|
ELSIF p.types.0 == "Array";
|
||||||
|
val = '[]';
|
||||||
|
ELSE;
|
||||||
|
val = '"missing"';
|
||||||
|
END;
|
||||||
|
props = props _ ' "' _ p.name _ '" : ' _ val;
|
||||||
|
END;
|
||||||
|
props = props _ '
|
||||||
|
';
|
||||||
|
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: </api/' _ id _ '/>; rel=collection
|
||||||
|
Link: <http://purl.org/sipwise/ngcp-api/>; rel=profile
|
||||||
|
Link: </api/' _ id _ '/1>; rel="item self"
|
||||||
|
|
||||||
|
{
|
||||||
|
"_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 _ ' }';
|
||||||
|
|
||||||
|
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
||||||
|
-%]
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h[% level + 2 %]>Create a new <i>[% id %]</i> item</h[% level + 2 %]>
|
||||||
|
<p>
|
||||||
|
[%
|
||||||
|
props = '';
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
NEXT IF p.types.0 == 'null';
|
||||||
|
IF p.types.0 == "Number";
|
||||||
|
val = 4;
|
||||||
|
ELSIF p.types.0 == "String";
|
||||||
|
val = '"test"';
|
||||||
|
ELSIF p.types.0 == "Boolean";
|
||||||
|
val = 'true';
|
||||||
|
ELSIF p.types.0 == "Array";
|
||||||
|
val = '[]';
|
||||||
|
ELSE;
|
||||||
|
val = '"missing"';
|
||||||
|
END;
|
||||||
|
props = props _ '"' _ p.name _ '" : ' _ val;
|
||||||
|
props = props _ ', ';
|
||||||
|
END;
|
||||||
|
props = props.substr(0, props.length - 2);
|
||||||
|
|
||||||
|
cmd = 'curl -i -X POST -H \'Connection: close\' -H \'Content-Type: application/json\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/\' --data-binary \'{ ' _ props _ ' }\'';
|
||||||
|
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
|
||||||
|
|
||||||
|
props = '';
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
NEXT IF p.types.0 == 'null';
|
||||||
|
IF p.types.0 == "Number";
|
||||||
|
val = 4;
|
||||||
|
ELSIF p.types.0 == "String";
|
||||||
|
val = '"test"';
|
||||||
|
ELSIF p.types.0 == "Boolean";
|
||||||
|
val = 'true';
|
||||||
|
ELSIF p.types.0 == "Array";
|
||||||
|
val = '[]';
|
||||||
|
ELSE;
|
||||||
|
val = '"missing"';
|
||||||
|
END;
|
||||||
|
props = props _ ' "' _ p.name _ '" : ' _ val;
|
||||||
|
props = props _ ',
|
||||||
|
';
|
||||||
|
END;
|
||||||
|
props = props.substr(0, props.length - 2);
|
||||||
|
request =
|
||||||
|
'POST /api/' _ id _ '/ HTTP/1.1
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
' _ props _ '
|
||||||
|
}';
|
||||||
|
response =
|
||||||
|
'HTTP/1.1 201 Created
|
||||||
|
Location: /api/' _ id _ '/2';
|
||||||
|
|
||||||
|
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
||||||
|
%]
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h[% level + 2 %]>Update an existing <i>[% id %]</i> item</h[% level + 2 %]>
|
||||||
|
<p>
|
||||||
|
[%
|
||||||
|
props = '';
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
NEXT IF p.types.0 == 'null';
|
||||||
|
IF p.types.0 == "Number";
|
||||||
|
val = 4;
|
||||||
|
ELSIF p.types.0 == "String";
|
||||||
|
val = '"test"';
|
||||||
|
ELSIF p.types.0 == "Boolean";
|
||||||
|
val = 'true';
|
||||||
|
ELSIF p.types.0 == "Array";
|
||||||
|
val = '[]';
|
||||||
|
ELSE;
|
||||||
|
val = '"missing"';
|
||||||
|
END;
|
||||||
|
props = props _ '"' _ p.name _ '" : ' _ val;
|
||||||
|
props = props _ ', ';
|
||||||
|
END;
|
||||||
|
props = props.substr(0, props.length - 2);
|
||||||
|
|
||||||
|
cmd = 'curl -i -X PUT -H \'Connection: close\' -H \'Content-Type: application/json\' -H \'Prefer: return=minimal\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/2\' --data-binary \'{ ' _ props _ ' }\'';
|
||||||
|
INCLUDE helpers/api_command.tt cmd=cmd extended=1 level=level+3;
|
||||||
|
|
||||||
|
props = '';
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
NEXT IF p.types.0 == 'null';
|
||||||
|
IF p.types.0 == "Number";
|
||||||
|
val = 4;
|
||||||
|
ELSIF p.types.0 == "String";
|
||||||
|
val = '"test"';
|
||||||
|
ELSIF p.types.0 == "Boolean";
|
||||||
|
val = 'true';
|
||||||
|
ELSIF p.types.0 == "Array";
|
||||||
|
val = '[]';
|
||||||
|
ELSE;
|
||||||
|
val = '"missing"';
|
||||||
|
END;
|
||||||
|
props = props _ ' "' _ p.name _ '" : ' _ val;
|
||||||
|
props = props _ ',
|
||||||
|
';
|
||||||
|
END;
|
||||||
|
props = props.substr(0, props.length - 2);
|
||||||
|
request =
|
||||||
|
'PUT /api/' _ id _ '/2 HTTP/1.1
|
||||||
|
Content-Type: application/json
|
||||||
|
Prefer: return=minimal
|
||||||
|
|
||||||
|
{
|
||||||
|
' _ props _ '
|
||||||
|
}';
|
||||||
|
response =
|
||||||
|
'HTTP/1.1 204 No Content
|
||||||
|
Preference-Applied: return=minimal';
|
||||||
|
|
||||||
|
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
||||||
|
-%]
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h[% level + 2 %]>Update specific fields of an existing <i>systemcontacts</i> entry</h[% level + 2 %]>
|
||||||
|
<p>
|
||||||
|
[%
|
||||||
|
props = ''; rem = 0; rep = 0;
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
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\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/2\' --data-binary \'[ ' _ props _ ' ]\'';
|
||||||
|
INCLUDE helpers/api_command.tt cmd=cmd extended=1 level=level+3;
|
||||||
|
%]
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The PATCH method allows to operate on specific fields of an item. The <b>path</b> attribute can point to a normal property (e.g. /something) or to a specific element in an array (e.g. /something/0). Available <b>op</b> values are:
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>remove</b>
|
||||||
|
<p>Removes the property pointed to by <b>path</b>. You can point to a normal property (e.g. /something) or to a specific element in an array (e.g. /something/0).</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>replace</b>
|
||||||
|
<p>Replaces the value pointed to by <b>path</b> by the new value passed via <b>value</b>.</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>add</b>
|
||||||
|
<p>Adds a new property <b>path</b> by the new value passed via <b>value</b>.</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>copy, move</b>
|
||||||
|
<p>Copies or moves (copy, then remove) the value from property defined by <b>from</b> to the propery defined by <b>path</b>.</p>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[%
|
||||||
|
props = ''; rem = 0; rep = 0;
|
||||||
|
FOREACH p IN col.fields;
|
||||||
|
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);
|
||||||
|
|
||||||
|
request =
|
||||||
|
'PATCH /api/' _ id _ '/2 HTTP/1.1
|
||||||
|
Content-Type: application/json-patch+json
|
||||||
|
Prefer: return=minimal
|
||||||
|
|
||||||
|
[' _ props _ '
|
||||||
|
]';
|
||||||
|
response =
|
||||||
|
'HTTP/1.1 204 No Content
|
||||||
|
Preference-Applied: return=minimal';
|
||||||
|
|
||||||
|
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
||||||
|
-%]
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
[% # vim: set tabstop=4 syntax=html expandtab: -%]
|
@ -1,338 +0,0 @@
|
|||||||
<h[% level %] id="[% id %]">
|
|
||||||
[% IF uri -%]
|
|
||||||
<a href="[% uri %]" rel="collection">
|
|
||||||
[% END -%]
|
|
||||||
[% title %]
|
|
||||||
[% IF uri -%]
|
|
||||||
</a>
|
|
||||||
[% END -%]
|
|
||||||
</h[% level %]>
|
|
||||||
|
|
||||||
<h[% level + 1 %]>Description</h[% level + 1%]>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
The <a href="#rel-systemcontacts">systemcontacts</a> item is used to specify the contact information of <a href="#rel-contracts">peering and reseller contracts</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h[% level + 1 %]>Properties</h[% level + 1%]>
|
|
||||||
<ul id="[% id %]-props"></ul>
|
|
||||||
<script>
|
|
||||||
<![CDATA[
|
|
||||||
$(function() {
|
|
||||||
var items = [];
|
|
||||||
var props = '[% INSERT 'js/api/properties/systemcontacts-item.json' | replace('\'', '\\\'') | replace("\n", ' ') | replace('\\\"', '\\\\\"') -%]';
|
|
||||||
var jprops = $.parseJSON(props);
|
|
||||||
for(var key in jprops.properties) {
|
|
||||||
var prop = jprops.properties[key];
|
|
||||||
items.push('<li><b>' + key + '</b> (<i>' + prop.type + '</i>): ' + prop.description + '</li>');
|
|
||||||
}
|
|
||||||
$('#[% id %]-props').append(items.join(''));
|
|
||||||
});
|
|
||||||
]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h[% level + 1 %]>Relation Links</h[% level + 1%]>
|
|
||||||
<p>None</p>
|
|
||||||
<!--
|
|
||||||
<ul id="[% id %]-links"></ul>
|
|
||||||
<script>
|
|
||||||
<![CDATA[
|
|
||||||
$(function() {
|
|
||||||
var items = [];
|
|
||||||
var links = '[% INSERT 'js/api/links/customercontacts-item.json' | replace('\'', '\\\'') | replace("\n", ' ') | replace('\\\"', '\\\\\"') -%]';
|
|
||||||
var jlinks = $.parseJSON(links);
|
|
||||||
for(var key in jlinks._links) {
|
|
||||||
var link = jlinks._links[key];
|
|
||||||
items.push('<li><b>' + key + '</b> (<i>href</i>): ' + link.href + '</li>');
|
|
||||||
}
|
|
||||||
$('#[% id %]-links').append(items.join(''));
|
|
||||||
});
|
|
||||||
]]>
|
|
||||||
</script>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<h[% level + 1 %]>Examples</h[% level + 1 %]>
|
|
||||||
<div class="examples">
|
|
||||||
|
|
||||||
<h[% level + 2 %]>Request available HTTP methods on the URI</h[% level + 2 %]>
|
|
||||||
<p>
|
|
||||||
[%
|
|
||||||
cmd = 'curl -i -X OPTIONS -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem https://example.org:1443/api/systemcontacts/';
|
|
||||||
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
|
|
||||||
|
|
||||||
request = [
|
|
||||||
'OPTIONS /api/systemcontacts/ HTTP/1.1'
|
|
||||||
];
|
|
||||||
response = [
|
|
||||||
'HTTP/1.1 200 OK',
|
|
||||||
'Allow: GET, HEAD, OPTIONS, POST',
|
|
||||||
'<a href="#draft-wilde-accept-post">Accept-Post</a>: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/#rel-systemcontacts"',
|
|
||||||
];
|
|
||||||
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
|
||||||
-%]
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h[% level + 2 %]>Request the entire <i>systemcontacts</i> collection</h[% level + 2 %]>
|
|
||||||
<p>
|
|
||||||
<p>
|
|
||||||
You cannot request the entire collection at once, but instead you can simply page through the results. The response provides <i>prev</i> and <i>next</i> 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 <i>page</i> and <i>rows</i>. Default values are <i>page=1</i> and <i>rows=10</i>, if you do not provide them.
|
|
||||||
</p>
|
|
||||||
[%
|
|
||||||
cmd = 'curl -i -X GET -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/systemcontacts/?page=1&rows=2\'';
|
|
||||||
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
|
|
||||||
|
|
||||||
request = [
|
|
||||||
'GET /api/systemcontacts/ HTTP/1.1',
|
|
||||||
];
|
|
||||||
response = [
|
|
||||||
'HTTP/1.1 200 OK
|
|
||||||
Content-Type: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/"
|
|
||||||
Link: </api/systemcontacts/1>; rel="item http://purl.org/sipwise/ngcp-api/#rel-systemcontacts"
|
|
||||||
Link: </api/systemcontacts/2>; rel="item http://purl.org/sipwise/ngcp-api/#rel-systemcontacts"
|
|
||||||
Link: <http://purl.org/sipwise/ngcp-api/>; rel=profile
|
|
||||||
Link: </api/systemcontacts/?page=1&rows=2>; rel="collection self"
|
|
||||||
Link: </api/systemcontacts/?page=2&rows=2>; rel=next
|
|
||||||
|
|
||||||
{
|
|
||||||
"_embedded" : {
|
|
||||||
"ngcp:systemcontacts" : [
|
|
||||||
{
|
|
||||||
"_links" : {
|
|
||||||
"collection" : {
|
|
||||||
"href" : "/api/systemcontacts/"
|
|
||||||
},
|
|
||||||
"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/systemcontacts/1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"city" : null,
|
|
||||||
"company" : null,
|
|
||||||
"country" : null,
|
|
||||||
"email" : "default-peering@default.invalid",
|
|
||||||
"firstname" : null,
|
|
||||||
"lastname" : null,
|
|
||||||
"phonenumber" : null,
|
|
||||||
"postcode" : null,
|
|
||||||
"street" : null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"_links" : {
|
|
||||||
"collection" : {
|
|
||||||
"href" : "/api/systemcontacts/"
|
|
||||||
},
|
|
||||||
"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/systemcontacts/2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"city" : null,
|
|
||||||
"company" : null,
|
|
||||||
"country" : null,
|
|
||||||
"email" : "default-reseller@default.invalid",
|
|
||||||
"firstname" : null,
|
|
||||||
"lastname" : null,
|
|
||||||
"phonenumber" : null,
|
|
||||||
"postcode" : null,
|
|
||||||
"street" : null
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"_links" : {
|
|
||||||
"curies" : {
|
|
||||||
"href" : "http://purl.org/sipwise/ngcp-api/#rel-{rel}",
|
|
||||||
"name" : "ngcp",
|
|
||||||
"templated" : true
|
|
||||||
},
|
|
||||||
"next" : {
|
|
||||||
"href" : "/api/systemcontacts/?page=2&rows=2"
|
|
||||||
},
|
|
||||||
"ngcp:systemcontacts" : [
|
|
||||||
{
|
|
||||||
"href" : "/api/systemcontacts/1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"href" : "/api/systemcontacts/2"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"profile" : {
|
|
||||||
"href" : "http://purl.org/sipwise/ngcp-api/"
|
|
||||||
},
|
|
||||||
"self" : {
|
|
||||||
"href" : "/api/systemcontacts/?page=1&rows=2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"total_count" : 57
|
|
||||||
}'
|
|
||||||
];
|
|
||||||
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
|
||||||
-%]
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h[% level + 2 %]>Request a specific <i>systemcontacts</i> item</h[% level + 2 %]>
|
|
||||||
<p>
|
|
||||||
[%
|
|
||||||
cmd = 'curl -i -X GET -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/systemcontacts/3\'';
|
|
||||||
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
|
|
||||||
|
|
||||||
request = [
|
|
||||||
'GET /api/systemcontacts/3 HTTP/1.1',
|
|
||||||
];
|
|
||||||
response = [
|
|
||||||
'HTTP/1.1 200 OK
|
|
||||||
Content-Type: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/"
|
|
||||||
Link: </api/systemcontacts/>; rel=collection
|
|
||||||
Link: <http://purl.org/sipwise/ngcp-api/>; rel=profile
|
|
||||||
Link: </api/systemcontacts/3>; rel="item self"
|
|
||||||
|
|
||||||
{
|
|
||||||
"_links" : {
|
|
||||||
"collection" : {
|
|
||||||
"href" : "/api/systemcontacts/"
|
|
||||||
},
|
|
||||||
"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/systemcontacts/3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"city" : null,
|
|
||||||
"company" : null,
|
|
||||||
"country" : null,
|
|
||||||
"email" : "default-reseller@default.invalid",
|
|
||||||
"firstname" : null,
|
|
||||||
"lastname" : null,
|
|
||||||
"phonenumber" : null,
|
|
||||||
"postcode" : null,
|
|
||||||
"street" : null
|
|
||||||
}'
|
|
||||||
];
|
|
||||||
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
|
||||||
-%]
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h[% level + 2 %]>Create a new <i>systemcontacts</i> entry</h[% level + 2 %]>
|
|
||||||
<p>
|
|
||||||
[%
|
|
||||||
cmd = 'curl -i -X POST -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.com:1443/api/systemcontacts/\' --data-binary \'{ "firstname": "John", "lastname": "Doe", "city": null, "company": null, "country": null, "phonenumber": null, "postcode": null, "street": null, "email": "john.doe@reseller.invalid", "reseller_id": 1 }\' -H \'Content-Type: application/json\'';
|
|
||||||
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
|
|
||||||
|
|
||||||
request = [
|
|
||||||
'POST /api/systemcontacts/ HTTP/1.1',
|
|
||||||
'Content-Type: application/json',
|
|
||||||
'',
|
|
||||||
'{
|
|
||||||
"firstname": "John",
|
|
||||||
"lastname": "Doe",
|
|
||||||
"email": "john.doe@reseller.invalid",
|
|
||||||
"city": null,
|
|
||||||
"company": null,
|
|
||||||
"country": null,
|
|
||||||
"phonenumber": null,
|
|
||||||
"postcode": null,
|
|
||||||
"street": null
|
|
||||||
}',
|
|
||||||
];
|
|
||||||
response = [
|
|
||||||
'HTTP/1.1 201 Created
|
|
||||||
Location: /api/systemcontacts/280'
|
|
||||||
];
|
|
||||||
|
|
||||||
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
|
||||||
-%]
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h[% level + 2 %]>Update an existing <i>systemcontacts</i> entry</h[% level + 2 %]>
|
|
||||||
<p>
|
|
||||||
[%
|
|
||||||
cmd = 'curl -i -X PUT -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/systemcontacts/10\' --data-binary \'{ "firstname": "John", "lastname": "Doe", "email": "something.else@reseller.invalid", "city": null, "company": null, "country": null, "phonenumber": null, "postcode": null, "street": null }\' -H \'Content-Type: application/json\' -H \'Prefer: return=minimal\'';
|
|
||||||
INCLUDE helpers/api_command.tt cmd=cmd extended=1 level=level+3;
|
|
||||||
|
|
||||||
request = [
|
|
||||||
'PUT /api/contacts/10 HTTP/1.1',
|
|
||||||
'Content-Type: application/json',
|
|
||||||
'Prefer: return=minimal',
|
|
||||||
'',
|
|
||||||
'{
|
|
||||||
"firstname": "John",
|
|
||||||
"lastname": "Doe",
|
|
||||||
"email": "something.else@reseller.invalid",
|
|
||||||
"city": null,
|
|
||||||
"company": null,
|
|
||||||
"country": null,
|
|
||||||
"phonenumber": null,
|
|
||||||
"postcode": null,
|
|
||||||
"street": null
|
|
||||||
}',
|
|
||||||
];
|
|
||||||
response = [
|
|
||||||
'HTTP/1.1 204 No Content',
|
|
||||||
'Preference-Applied: return=minimal',
|
|
||||||
];
|
|
||||||
|
|
||||||
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
|
||||||
-%]
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h[% level + 2 %]>Update specific fields of an existing <i>systemcontacts</i> entry</h[% level + 2 %]>
|
|
||||||
<p>
|
|
||||||
[%
|
|
||||||
cmd = 'curl -i -X PATCH -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/systemcontacts/10 --data-binary \'[ { "op": "replace", "path": "/email", "value": "other.john.doe@reseller.invalid" }, { "op": "replace", "path": "/street", "value": "Some Street" } ]\' -H \'Content-Type: application/json-patch+json\' -H \'Prefer: return=minimal\'';
|
|
||||||
INCLUDE helpers/api_command.tt cmd=cmd extended=1 level=level+3;
|
|
||||||
|
|
||||||
request = [
|
|
||||||
'PATCH /api/systemcontacts/10 HTTP/1.1',
|
|
||||||
'Content-Type: application/json-patch+json',
|
|
||||||
'Prefer: return=minimal',
|
|
||||||
'',
|
|
||||||
'[
|
|
||||||
{
|
|
||||||
"op": "replace",
|
|
||||||
"path": "/email",
|
|
||||||
"value": "other.john.doe@reseller.invalid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"op": "replace",
|
|
||||||
"path": "/street",
|
|
||||||
"value": "Some Street"
|
|
||||||
}
|
|
||||||
]',
|
|
||||||
];
|
|
||||||
response = [
|
|
||||||
'HTTP/1.1 204 No Content',
|
|
||||||
'Preference-Applied: return=minimal',
|
|
||||||
];
|
|
||||||
|
|
||||||
INCLUDE helpers/api_req_res.tt request=request response=response level=level+3;
|
|
||||||
-%]
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Note that for PATCH, the body must be a JSON Array, even if there is only one 'op' entry.
|
|
||||||
</p>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
[% # vim: set tabstop=4 syntax=html expandtab: -%]
|
|
Loading…
Reference in new issue