-
Notifications
You must be signed in to change notification settings - Fork 12
RESTful API
User can use InFactory regardless of the development environment via RESTful API of InFactory. RESTful API is based on CRUD function on IndoorGML complex features. Users can create IndoorGML by writing their own indoor space information according to the predefined JSON(Javascript Object Notation) based form.
All IndoorGML complex features can be represented by this JSON format. The details are described at JSON-format
First of all, the users need to implement their own client program which sends HTTP requests to the server. If there is no client program, it is recommended to use InSomnia, which is a debugging tool for RESTful API by by communicating HTTP request to the server program.
- POST: Request to create a new entity including a document and the features in IndoorGML
- GET: Retrieve information from InFactory server.
- PUT: Request to update the existing entity. InFactory supports fully-patched Update.
- DELETE: Request to remove a resource; however, the resource does not have to be removed immediately.
After installing Infactory as explained in Readme, you have to make InFactory server ready to receive the HTTP requests from your client.
$ mvn clean install
$ mvn jetty:run "-Djetty.port=9797"
You can create an IndoorGML document by sending a set of POST requests to the InFactory server. The creation process is in general composed of the following steps;
- Step 1: Creation of IndoorGML document
- Step 2: Creation of IndoorGML Features
- Step 3:
- The information about a document is needed to be created first.
- Every request url contains the identifier of the document.
- example :
http://localhost:9797/documents/doc1
- example :
- InFactory accepts the http request regardless of the tree structure of IndoorGML for convenience. But just for easy memorization of what is created or not, here are some examples of some data flows that can be refered.
- example : If a State feature is created first, then all the other features such as SpaceLayers, SpaceLayer, Nodes can be created later than the State, but until right before sending the GET request of the document, those features are needed to be created.
IndoorFeatures
|-> PrimalSpaceFeatures
|-> CellSpace
|-> CellSpaceBoundary
|-> MultiLayeredGraph -> SpaceLayers -> SpaceLayer
|-> Nodes -> State
|-> Edges -> Transition
var req = new XMLHttpRequest();
req.open('POST', 'http://localhost:9797/documents/:id');
req.setRequestHeader('Content-type', 'application/json');
req.send(JSON.stringify({
docId: "doc1"
}));
req.onreadystatechange = function (e) {
if (req.readyState === XMLHttpRequest.DONE) {
if(req.status === 201) {
console.log(req.responseText);
} else {
console.log("Error!");
}
}
};
First of all, It is needed to create a document
/documents/:id
- parameter :
id=[alphanumeric id which starts as a alphabet]
$ POST http://localhost:9797/documents/doc1
- Content-Type : "application/json"
- Accept : "application/json"
{
"id":"doc1"
}
- Status : 201 created / 404 NOT FOUND
- Content-Type : None
Next, the Indoorfeatures feature can be created by sending the below request to the server.
InFactory support unordered creation of the feature in IndoorGML.
/documents/:docId/indoorfeatures/:id
- parameter :
docId | id =[alphanumeric id which starts as a alphabet]
$ POST http://localhost:9797/documents/doc1/indoorfeatures/if1
- Content-Type : "application/json"
- Accept : "application/json"
{
"docId":"doc1", //the id of the document which this elements are contained.
"id":"lf1" //the id of the feature.
}
- Status : 201 created / 404 NOT FOUND
- Content-Type : None
/documents/:docId/primalspacefeatures/:id
- parameter :
docId | id =[alphanumeric id which starts as a alphabet]
$ POST http://localhost:9797/documents/doc1primalspacefeatures/pf1
- Content-Type : "application/json"
- Accept : "application/json"
{
"docId":"doc1",
"parentId":"lf1",
"id":"psf1"
}
- Status : 201 created / 404 NOT FOUND
- Content-Type : None
/documents/:docId/cellspace/:id
- parameter :
docId | id =[alphanumeric id which starts as a alphabet]
$ POST http://localhost:9797/documents/doc1/cellspace/c1
- Content-Type : "application/json"
- Accept : "application/json"
{
"docId":"doc1",
"parentId":"psf1",
"id":"c1",
"geometry": {
"type" : "Solid",
"coordinates" : "SOLID (( ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)), ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)), ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)) ))",
"properties" : {
"id" : "c1g",
"type" : "wkt"
}
}
}
- Status : 201 created / 404 NOT FOUND
- Content-Type : None
var req = new XMLHttpRequest();
req.open('GET', 'http://localhost:9797/documents/doc1/cellspace/c1');
req.send();
req.onreadystatechange = function (e) {
if (req.readyState === XMLHttpRequest.DONE) {
if(req.status === 302) {
console.log(req.responseText);
} else {
console.log("Error!");
}
}
};
The request is sent as the below.
/documents/:docId
- parameter :
docId =[alphanumeric id which starts as a alphabet]
$ GET http://localhost:9797/documents/doc1/
- Content-Type : None
- Accept : None
- Status : 302 FOUND / 404 NOT FOUND
- Content-Type : "application/xml"
<IndoorFeatures
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.opengis.net/indoorgml/1.0/core"
xmlns:navi="http://www.opengis.net/indoorgml/1.0/navigation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" gml:id="lf1" xsi:schemaLocation="http://www.opengis.net/indoorgml/1.0/core http://schemas.opengis.net/indoorgml/1.0/indoorgmlcore.xsd http://www.opengis.net/indoorgml/1.0/navigation http://schemas.opengis.net/indoorgml/1.0/indoorgmlnavi.xsd">
<gml:boundedBy xsi:nil="true"/>
<primalSpaceFeatures>
<PrimalSpaceFeatures gml:id="psf1">
<gml:boundedBy xsi:nil="true"/>
<cellSpaceMember>
<CellSpace gml:id="c1">
<gml:boundedBy xsi:nil="true"/>
<cellSpaceGeometry>
<Geometry3D>
<gml:Solid gml:id="c1g">
<gml:exterior>
<gml:Shell>
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos srsDimension="3">0.0 0.0 0.0</gml:pos>
<gml:pos srsDimension="3">0.0 1.0 0.0</gml:pos>
<gml:pos srsDimension="3">1.0 1.0 0.0</gml:pos>
<gml:pos srsDimension="3">1.0 0.0 0.0</gml:pos>
<gml:pos srsDimension="3">0.0 0.0 0.0</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos srsDimension="3">0.0 0.0 0.0</gml:pos>
<gml:pos srsDimension="3">0.0 1.0 0.0</gml:pos>
<gml:pos srsDimension="3">0.0 1.0 1.0</gml:pos>
<gml:pos srsDimension="3">0.0 0.0 1.0</gml:pos>
<gml:pos srsDimension="3">0.0 0.0 0.0</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos srsDimension="3">0.0 0.0 0.0</gml:pos>
<gml:pos srsDimension="3">1.0 0.0 0.0</gml:pos>
<gml:pos srsDimension="3">1.0 0.0 1.0</gml:pos>
<gml:pos srsDimension="3">0.0 0.0 1.0</gml:pos>
<gml:pos srsDimension="3">0.0 0.0 0.0</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos srsDimension="3">1.0 1.0 1.0</gml:pos>
<gml:pos srsDimension="3">1.0 0.0 1.0</gml:pos>
<gml:pos srsDimension="3">0.0 0.0 1.0</gml:pos>
<gml:pos srsDimension="3">0.0 1.0 1.0</gml:pos>
<gml:pos srsDimension="3">1.0 1.0 1.0</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos srsDimension="3">1.0 1.0 1.0</gml:pos>
<gml:pos srsDimension="3">1.0 0.0 1.0</gml:pos>
<gml:pos srsDimension="3">1.0 0.0 0.0</gml:pos>
<gml:pos srsDimension="3">1.0 1.0 0.0</gml:pos>
<gml:pos srsDimension="3">1.0 1.0 1.0</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos srsDimension="3">1.0 1.0 1.0</gml:pos>
<gml:pos srsDimension="3">1.0 1.0 0.0</gml:pos>
<gml:pos srsDimension="3">0.0 1.0 0.0</gml:pos>
<gml:pos srsDimension="3">0.0 1.0 1.0</gml:pos>
<gml:pos srsDimension="3">1.0 1.0 1.0</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
</gml:Shell>
</gml:exterior>
</gml:Solid>
</Geometry3D>
</cellSpaceGeometry>
</CellSpace>
</cellSpaceMember>
</PrimalSpaceFeatures>
</primalSpaceFeatures>
</IndoorFeatures>
/documents/:docId/cellspace/:id
- parameter :
docId | id =[alphanumeric id which starts as a alphabet]
$ GET http://localhost:9797/documents/doc1/cellspace/c1
- Content-Type : None
- Accept : None
- Status : 302 FOUND / 404 NOT FOUND
- Content-Type : "application/json"
{
"docId":"doc1",
"parentId":"psf1",
"id":"c1",
"geometry": {
"type" : "Solid",
"coordinates" : "SOLID (( ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)), ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)), ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)) ))",
"properties" : {
"id" : "c1g",
"type" : "wkt"
}
}
}
InFactory changes the contents of the existing features fully when Infactory receives "PUT" request.
var req = new XMLHttpRequest();
req.open('PUT', 'http://localhost:9797/documents/doc1/cellspace/c1');
req.setRequestHeader('Content-type', 'application/json');
req.send(JSON.stringify({
type : "CellSpace",
docId : "doc1" ,
parentId : "psf1",
id : "c1",
geometry : {
"type" : "Solid",
coordinates : "SOLID (( ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)), ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)), ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)) ))",
properties : {
id : "c1g",
type : "wkt"
}
}));
req.onreadystatechange = function (e) {
if (req.readyState === XMLHttpRequest.DONE) {
if(req.status === 200) {
console.log(req.responseText);
} else {
console.log("Error!");
}
}
};
/documents/:docId/cellspace/:id
- parameter :
docId | id =[alphanumeric id which starts as a alphabet]
$ PUT http://localhost:9797/documents/doc1/cellspace/c1
- Content-Type : "application/json"
- Accept : "application/json"
{
"docId":"doc1",
"parentId":"psf1",
"id":"c1",
"geometry": {
"type" : "Solid",
"coordinates" : "SOLID (( ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)), ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)), ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)) ))",
"properties" : {
"id" : "c1g",
"type" : "wkt"
}
}
}
- Status : 201 CREATED / 404 NOT FOUND
- Content-Type : None
This request removes CellSpace "c1" at the server.
var req = new XMLHttpRequest();
req.open('DELETE', 'http://localhost:9797/documents/doc1/cellspace/c1');
req.send();
req.onreadystatechange = function (e) {
if (req.readyState === XMLHttpRequest.DONE) {
if(req.status === 204) {
console.log(req.responseText);
} else {
console.log("Error!");
}
}
};
/documents/:docId/cellspace/:id
- parameter :
docId | id =[alphanumeric id which starts as a alphabet]
$ DELETE http://localhost:9797/documents/doc1/cellspace/c1
- Content-Type : None
- Accept : None
- Status : 204 NO CONTENT / 404 NOT FOUND
- Content-Type : None