generated from intersystems-community/rest-api-contest-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
24 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
## rest-api-contest-template | ||
This is a template for for a InterSystems IRIS REST API Contest. | ||
It has an example of REST API with CRUD actions for a Sample Person peristent class. | ||
## IRIS Interoperability Production Manager | ||
This is REST API to manage IRIS Interoperability Productions. | ||
|
||
## Inspiration | ||
To make an easy template to start building REST API in IRIS | ||
|
||
## What it does | ||
Creates /crud web app in IRIS and CRUD endpoints to play with persistent data in Sample.Person class. | ||
It uses [swagger-ui](https://openexchange.intersystems.com/package/iris-web-swagger-ui) module to provide documentation and test environment for API. | ||
 | ||
|
||
|
||
## Challenges I ran into | ||
no challenges | ||
|
||
## Accomplishments that I proud of | ||
Easy template with self documented API spec installed with one ZPM command or docker-compose build | ||
|
||
## What I learned | ||
a lot! | ||
Production manager allows: | ||
* Create a new production | ||
* Start and Stop Production | ||
* Get Production status and production details | ||
* Add new Business Host to the production | ||
* Change Settings for Production and Business Hosts | ||
|
||
## Built with | ||
Using VSCode and ObjectScript plugin, IRIS Community Edition in Docker, ZPM, IRIS openapi API | ||
|
||
## Installation with ZPM | ||
|
||
zpm:USER>install rest-api-contest-template | ||
zpm:USER>install production-manager | ||
|
||
## Installation with Docker | ||
|
||
|
@@ -36,7 +26,7 @@ Make sure you have [git](https://git-scm.com/book/en/v2/Getting-Started-Installi | |
Clone/git pull the repo into any local directory e.g. like it is shown below: | ||
|
||
``` | ||
$ git clone [email protected]:intersystems-community/rest-api-contest-template.git | ||
$ git clone [email protected]:nsolov/production-manager.git | ||
``` | ||
|
||
Open the terminal in this directory and run: | ||
|
@@ -47,9 +37,9 @@ $ docker-compose up -d --build | |
|
||
## How to Work With it | ||
|
||
This template creates /crud REST web-application on IRIS which implements 4 types of communication: GET, POST, PUT and DELETE aka CRUD operations. | ||
The API is available on localhost:52773/crud/ | ||
This REST API goes with OpenAPI (swagger) documentation. you can check it localhost:52773/crud/_spec | ||
This app creates /production REST web-application on IRIS which implements 4 types of communication: GET, POST, PUT and DELETE aka CRUD operations. | ||
The API is available on localhost:9098/production/ | ||
This REST API goes with OpenAPI (swagger) documentation. you can check it localhost:9098/production/_spec | ||
THis spec can be examined with different tools, such as [SwaggerUI](https://swagger.io/tools/swagger-ui/), [Postman](postman.com), etc. | ||
Or you can install [swagger-ui](https://openexchange.intersystems.com/package/iris-web-swagger-ui) with: | ||
``` | ||
|
@@ -58,87 +48,4 @@ zpm:IRISAPP>install swagger-ui | |
And check the documentation on localhost:52773/swagger-ui/index.html | ||
|
||
|
||
# Testing GET requests | ||
|
||
To test GET you need to have some data. You can create it with POST request (see below), or you can create some fake testing data. to do that open IRIS terminal and call: | ||
|
||
``` | ||
IRISAPP>do ##class(Sample.Person).AddTestData(10) | ||
``` | ||
This will create 10 random records in Sample.Person class. | ||
|
||
|
||
You can get swagger Open API 2.0 documentation on: | ||
``` | ||
localhost:yourport/_spec | ||
``` | ||
|
||
This REST API exposes two GET requests: all the data and one record. | ||
To get all the data in JSON call: | ||
|
||
``` | ||
localhost:52773/crud/persons/all | ||
``` | ||
|
||
To request the data for a particular record provide the id in GET request like 'localhost:52773/crud/persons/id' . E.g.: | ||
|
||
``` | ||
localhost:52773/crud/persons/1 | ||
``` | ||
|
||
This will return JSON data for the person with ID=1, something like that: | ||
|
||
``` | ||
{"Name":"Elon Mask","Title":"CEO","Company":"Tesla","Phone":"123-123-1233","DOB":"1982-01-19"} | ||
``` | ||
|
||
# Testing POST request | ||
|
||
Create a POST request e.g. in Postman with raw data in JSON. e.g. | ||
|
||
``` | ||
{"Name":"Elon Mask","Title":"CEO","Company":"Tesla","Phone":"123-123-1233","DOB":"1982-01-19"} | ||
``` | ||
|
||
Adjust the authorisation if needed - it is basic for container with default login and password for IRIR Community edition container | ||
|
||
and send the POST request to localhost:52773/crud/persons/ | ||
|
||
This will create a record in Sample.Person class of IRIS. | ||
|
||
# Testing PUT request | ||
|
||
PUT request could be used to update the records. This needs to send the similar JSON as in POST request above supplying the id of the updated record in URL. | ||
E.g. we want to change the record with id=5. Prepare in Postman the JSON in raw like following: | ||
|
||
``` | ||
{"Name":"Jeff Besos","Title":"CEO","Company":"Amazon","Phone":"123-123-1233","DOB":"1982-01-19"} | ||
``` | ||
|
||
and send the put request to: | ||
``` | ||
localhost:52773/crud/persons/5 | ||
``` | ||
|
||
# Testing DELETE request | ||
|
||
For delete request this REST API expects only the id of the record to delete. E.g. if the id=5 the following DELETE call will delete the record: | ||
|
||
``` | ||
localhost:52773/crud/persons/5 | ||
``` | ||
|
||
## How to start coding | ||
This is a template, so you can use a template button on Github to create your own copy of this repository. | ||
The repository is ready to code in VSCode with ObjectScript plugin. | ||
Install [VSCode](https://code.visualstudio.com/) and [ObjectScript](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript) plugin and open the folder in VSCode. | ||
Once you start IRIS container VSCode connects to it and you can edit, compile and debug ObjectScript code. | ||
Open /src/cls/PackageSample/ObjectScript.cls class and try to make changes - it will be compiled in running IRIS docker container. | ||
|
||
Feel free to delete PackageSample folder and place your ObjectScript classes in a form | ||
/src/cls/Package/Classname.cls | ||
|
||
The script in Installer.cls will import everything you place under /src/cls into IRIS. | ||
|
||
## Collaboration | ||
Any collaboration is very welcome! Fork and send Pull requests! | ||
# Testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/Demo/Production.cls → src/RestProduction/Demo/Production.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"info":{"title":"REST Production Manager","description":"","version":"0.1"},"basePath":"/production","paths":{"/stop/{production}":{"get":{"operationId":"Stop","summary":"Start Production ++ ","x-ISC_ServiceMethod":"Stop","parameters":[{"name":"production","in":"path","required":true,"type":"string"}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/start/{production}":{"get":{"operationId":"Start","summary":"Start Production ++ ","x-ISC_ServiceMethod":"Start","parameters":[{"name":"production","in":"path","required":true,"type":"string"}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/status/{production}":{"get":{"operationId":"Status","summary":"Get Production Status ++ ","x-ISC_ServiceMethod":"Status","parameters":[{"name":"production","in":"path","required":true,"type":"string"}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/summary/{production}":{"get":{"operationId":"Summary","summary":"Get Production Summary ++ ","x-ISC_ServiceMethod":"Summary","parameters":[{"name":"production","in":"path","required":true,"type":"string"}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/productions":{"get":{"operationId":"ProductionList","summary":"Get List of all productions in current namespace and their statuses ++ ","x-ISC_ServiceMethod":"ProductionList","responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/productions/{production}":{"get":{"operationId":"GetProductionSettings","summary":"Get Production Settings and production Items ","x-ISC_ServiceMethod":"GetProductionSettings","parameters":[{"name":"production","in":"path","required":true,"type":"string"}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}},"post":{"operationId":"AddProduction","summary":"Create new Production","x-ISC_ServiceMethod":"AddProduction","parameters":[{"name":"production","in":"path","required":true,"type":"string"},{"name":"payloadBody","in":"body","description":"Request body contents","required":false,"schema":{"type":"string"}}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}},"put":{"operationId":"UpdateProductionSettings","summary":"Update Production Settings","x-ISC_ServiceMethod":"UpdateProductionSettings","parameters":[{"name":"production","in":"path","required":true,"type":"string"},{"name":"payloadBody","in":"body","description":"Request body contents","required":false,"schema":{"type":"string"}}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/items/{production}/{item}":{"get":{"operationId":"GetItemSettings","summary":"Get Item Settings","x-ISC_ServiceMethod":"GetItemSettings","parameters":[{"name":"production","in":"path","required":true,"type":"string"},{"name":"item","in":"path","required":true,"type":"string"}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}},"post":{"operationId":"AddItem","summary":"Add Item to the Production","x-ISC_ServiceMethod":"AddItem","parameters":[{"name":"production","in":"path","required":true,"type":"string"},{"name":"item","in":"path","required":true,"type":"string"},{"name":"payloadBody","in":"body","description":"Request body contents","required":false,"schema":{"type":"string"}}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}},"put":{"operationId":"UpdateItemSettings","summary":"Update Item Settings","x-ISC_ServiceMethod":"UpdateItemSettings","parameters":[{"name":"production","in":"path","required":true,"type":"string"},{"name":"item","in":"path","required":true,"type":"string"},{"name":"payloadBody","in":"body","description":"Request body contents","required":false,"schema":{"type":"string"}}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}},"delete":{"operationId":"DeleteItem","summary":"Delete Item ","x-ISC_ServiceMethod":"DeleteItem","parameters":[{"name":"production","in":"path","required":true,"type":"string"},{"name":"item","in":"path","required":true,"type":"string"}],"responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/_ping":{"get":{"operationId":"Ping","x-ISC_ServiceMethod":"Ping","responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}},"/_spec":{"get":{"summary":"Get Swagger Specifiacation","x-ISC_ServiceMethod":"SwaggerSpec","operationId":"SwaggerSpec","responses":{"default":{"description":"(Unexpected Error)"},"200":{"description":"(Expected Result)"}}}}},"swagger":"2.0","host":"localhost:9098"} |