Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nsolov committed Apr 25, 2020
1 parent cce3ddb commit 9d38203
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 116 deletions.
121 changes: 14 additions & 107 deletions README.md
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.
![rest_contest](https://user-images.githubusercontent.com/2781759/79133636-084c6b80-7db5-11ea-8a2c-eab346ea70f9.gif)


## 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

Expand All @@ -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:
Expand All @@ -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:
```
Expand All @@ -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
4 changes: 2 additions & 2 deletions module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Document name="production-manager.ZPM">
<Module>
<Name>production-manager</Name>
<Version>1.0.0</Version>
<Version>1.0.3</Version>
<Packaging>module</Packaging>
<SourcesRoot>src</SourcesRoot>
<Resource Name="RestProduction.PKG"/>
Expand All @@ -12,7 +12,7 @@
Url="/production"
Recurse="1"
MatchRoles=":{$dbrole}"
PasswordAuthEnabled="0"
PasswordAuthEnabled="1"
UnauthenticatedEnabled="0"
DispatchClass="RestProduction.REST"
ServeFiles="1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Class Demo.Message Extends Ens.Request
Class RestProduction.Demo.Message Extends Ens.Request
{

Property currency As %String;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Class Demo.Operation Extends Ens.BusinessOperation
Class RestProduction.Demo.Operation Extends Ens.BusinessOperation
{

Parameter ADAPTER = "EnsLib.File.OutboundAdapter";
Expand All @@ -9,7 +9,7 @@ Property FileName As %String [ InitialExpression = "out.txt" ];

Parameter SETTINGS = "FileName:MySettings";

Method WriteToFile(pRequest As Demo.Message, Output pResponse As Ens.Response) As %Status
Method WriteToFile(pRequest As RestProduction.Demo.Message, Output pResponse As Ens.Response) As %Status
{
Set tSC = $$$OK
Set tSC = ..Adapter.PutLine(..FileName, pRequest.AsString())
Expand All @@ -19,7 +19,7 @@ Method WriteToFile(pRequest As Demo.Message, Output pResponse As Ens.Response) A
XData MessageMap
{
<MapItems>
<MapItem MessageType="Demo.Message">
<MapItem MessageType="RestProduction.Demo.Message">
<Method>WriteToFile</Method>
</MapItem>
</MapItems>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Class Demo.Production Extends Ens.Production
Class RestProduction.Demo.Production Extends Ens.Production
{

XData ProductionDefinition
{
<Production Name="Demo.Production">
<Production Name="RestProduction.Demo.Production">
<ActorPoolSize>1</ActorPoolSize>
<Item Name="BO1"
ClassName="Demo.Operation"
ClassName="RestProduction.Demo.Operation"
PoolSize="1" Enabled="true" Foreground="false" InactivityTimeout="0">
</Item>
</Production>
Expand Down
1 change: 1 addition & 0 deletions swagger.json
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"}

0 comments on commit 9d38203

Please sign in to comment.