Skip to content

Commit dc916b8

Browse files
committed
Initial commit
0 parents  commit dc916b8

16 files changed

+679
-0
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/.DS_Store

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.sh text eol=lf
2+
*.cls text eol=lf
3+
*.mac text eol=lf
4+
*.int text eol=lf
5+
Dockerfil* text eol=lf

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+

.vscode/launch.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "objectscript",
6+
"request": "launch",
7+
"name": "ObjectScript Debug Class",
8+
"program": "##class(PackageSample.ObjectScript).Test()",
9+
},
10+
{
11+
"type": "objectscript",
12+
"request": "attach",
13+
"name": "ObjectScript Attach",
14+
"processId": "${command:PickProcess}",
15+
"system": true
16+
}
17+
]
18+
}

.vscode/settings.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"files.associations": {
3+
4+
"Dockerfile*": "dockerfile",
5+
},
6+
"objectscript.conn" :{
7+
"ns": "IRISAPP",
8+
"active": true,
9+
"docker-compose": {
10+
"service": "iris",
11+
"internalPort": 52773
12+
}
13+
},
14+
"objectscript.conn.active": true,
15+
16+
17+
18+
}

Dockerfile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
ARG IMAGE=intersystems/iris:2019.1.0S.111.0
2+
ARG IMAGE=store/intersystems/irishealth:2019.3.0.308.0-community
3+
ARG IMAGE=store/intersystems/iris-community:2019.3.0.309.0
4+
ARG IMAGE=store/intersystems/iris-community:2019.4.0.379.0
5+
ARG IMAGE=store/intersystems/iris-community:2020.1.0.197.0
6+
ARG IMAGE=intersystemsdc/iris-community:2020.1.0.209.0-zpm
7+
FROM $IMAGE
8+
9+
USER root
10+
11+
WORKDIR /opt/irisapp
12+
RUN chown ${ISC_PACKAGE_MGRUSER}:${ISC_PACKAGE_IRISGROUP} /opt/irisapp
13+
14+
USER irisowner
15+
16+
COPY Installer.cls .
17+
COPY src src
18+
COPY irissession.sh /
19+
SHELL ["/irissession.sh"]
20+
21+
RUN \
22+
do $SYSTEM.OBJ.Load("Installer.cls", "ck") \
23+
set sc = ##class(App.Installer).setup() \
24+
zn "%SYS" \
25+
write "Create web application ..." \
26+
set webName = "/crud" \
27+
set webProperties("DispatchClass") = "Sample.PersonREST" \
28+
set webProperties("NameSpace") = "IRISAPP" \
29+
set webProperties("Enabled") = 1 \
30+
set webProperties("AutheEnabled") = 32 \
31+
set sc = ##class(Security.Applications).Create(webName, .webProperties) \
32+
write sc \
33+
write "Web application "_webName_" has been created!"
34+
35+
# bringing the standard shell back
36+
SHELL ["/bin/bash", "-c"]
37+
CMD [ "-l", "/usr/irissys/mgr/messages.log" ]

Dockerfile-zpm

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ARG IMAGE=intersystems/iris:2019.1.0S.111.0
2+
ARG IMAGE=store/intersystems/iris-community:2019.3.0.309.0
3+
ARG IMAGE=store/intersystems/iris-community:2019.4.0.379.0
4+
FROM $IMAGE
5+
6+
USER root
7+
8+
WORKDIR /opt/irisapp
9+
RUN chown ${ISC_PACKAGE_MGRUSER}:${ISC_PACKAGE_IRISGROUP} /opt/irisapp
10+
11+
12+
USER irisowner
13+
14+
RUN mkdir -p /tmp/deps \
15+
16+
&& cd /tmp/deps \
17+
18+
&& wget -q https://pm.community.intersystems.com/packages/zpm/latest/installer -O zpm.xml
19+
20+
21+
COPY Installer.cls .
22+
COPY src src
23+
COPY irissession.sh /
24+
25+
# running IRIS and open IRIS termninal in USER namespace
26+
SHELL ["/irissession.sh"]
27+
# below is objectscript executed in terminal
28+
# each row is what you type in terminal and Enter
29+
RUN \
30+
do $SYSTEM.OBJ.Load("Installer.cls", "ck") \
31+
set sc = ##class(App.Installer).setup() \
32+
zn "%SYS" \
33+
write "Create web application ..." \
34+
set webName = "/person" \
35+
set webProperties("DispatchClass") = "Sample.PersonREST" \
36+
set webProperties("NameSpace") = "IRISAPP" \
37+
set webProperties("Enabled") = 1 \
38+
set webProperties("AutheEnabled") = 32 \
39+
set sc = ##class(Security.Applications).Create(webName, .webProperties) \
40+
write sc \
41+
write "Web application "_webName_" has been created!" \
42+
Do $system.OBJ.Load("/tmp/deps/zpm.xml", "ck") \
43+
zn "IRISAPP"
44+
45+
46+
# bringing the standard shell back
47+
SHELL ["/bin/bash", "-c"]
48+
CMD [ "-l", "/usr/irissys/mgr/messages.log" ]

Installer.cls

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Class App.Installer
2+
{
3+
4+
XData setup
5+
{
6+
<Manifest>
7+
<Default Name="SourceDir" Value="#{$system.Process.CurrentDirectory()}src"/>
8+
9+
<Namespace Name="IRISAPP" Code="IRISAPP" Data="IRISAPP" Create="yes" Ensemble="no">
10+
11+
<Configuration>
12+
<Database Name="IRISAPP" Dir="/opt/irisapp/data" Create="yes"/>
13+
14+
<Import File="${SourceDir}" Flags="ck" Recurse="1"/>
15+
</Configuration>
16+
</Namespace>
17+
18+
</Manifest>
19+
}
20+
21+
ClassMethod setup(ByRef pVars, pLogLevel As %Integer = 3, pInstaller As %Installer.Installer, pLogger As %Installer.AbstractLogger) As %Status [ CodeMode = objectgenerator, Internal ]
22+
{
23+
#; Let XGL document generate code for this method.
24+
Quit ##class(%Installer.Manifest).%Generate(%compiledclass, %code, "setup")
25+
}
26+
27+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 InterSystems Developer Community
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
## intersystems-iris-docker-rest-template
2+
This is a template for for a REST API application with ObjectScript using Docker container for InterSystems IRIS
3+
The template goes also with a few files which let you immedietly compile your ObjecScript files in InterSystems IRIS Community Edition in a docker container
4+
5+
## Prerequisites
6+
This needs to have git and docker installed.
7+
8+
## Installation
9+
10+
Clone/git pull the repo into any local directory e.g. like it is shown below:
11+
12+
```
13+
$ git clone [email protected]:intersystems-community/objectscript-rest-docker-template.git
14+
```
15+
16+
Open the terminal in this directory and run:
17+
18+
```
19+
$ docker-compose up -d --build
20+
```
21+
22+
or install it with ZPM client:
23+
```
24+
zpm:USER>install objectscript-rest-template
25+
```
26+
27+
or open the folder in VSCode and do the following:
28+
![rest](https://user-images.githubusercontent.com/2781759/78183327-63569800-7470-11ea-8561-c3b547ce9001.gif)
29+
30+
31+
## How to Work With it
32+
33+
This template creates /crud REST web-application on IRIS which implements 4 types of communication: GET, POST, PUT and DELETE aka CRUD operations.
34+
These interface works with a sample persistent class Sample.Person.
35+
36+
# Testing GET requests
37+
38+
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 or web terminal on /localhost:52773/terminal/ and call:
39+
40+
```
41+
USER>do ##class(Sample.Person).AddTestData(10)
42+
```
43+
This will create 10 random records in Sample.Person class.
44+
45+
46+
You can get swagger Open API 2.0 documentation on:
47+
```
48+
localhost:yourport/_spec
49+
```
50+
51+
This REST API exposes two GET requests: all the data and one record.
52+
To get all the data in JSON call:
53+
54+
```
55+
localhost:52773/crud/persons/all
56+
```
57+
58+
To request the data for a particular record provide the id in GET request like 'localhost:52773/crud/persons/id' . E.g.:
59+
60+
```
61+
localhost:52773/crud/persons/1
62+
```
63+
64+
This will return JSON data for the person with ID=1, something like that:
65+
66+
```
67+
{"Name":"Elon Mask","Title":"CEO","Company":"Tesla","Phone":"123-123-1233","DOB":"1982-01-19"}
68+
```
69+
70+
# Testing POST request
71+
72+
Create a POST request e.g. in Postman with raw data in JSON. e.g.
73+
74+
```
75+
{"Name":"Elon Mask","Title":"CEO","Company":"Tesla","Phone":"123-123-1233","DOB":"1982-01-19"}
76+
```
77+
78+
Adjust the authorisation if needed - it is basic for container with default login and password for IRIR Community edition container
79+
80+
and send the POST request to localhost:52773/crud/persons/
81+
82+
This will create a record in Sample.Person class of IRIS.
83+
84+
# Testing PUT request
85+
86+
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.
87+
E.g. we want to change the record with id=5. Prepare in Postman the JSON in raw like following:
88+
89+
```
90+
{"Name":"Jeff Besos","Title":"CEO","Company":"Amazon","Phone":"123-123-1233","DOB":"1982-01-19"}
91+
```
92+
93+
and send the put request to:
94+
```
95+
localhost:52773/crud/persons/5
96+
```
97+
98+
# Testing DELETE request
99+
100+
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:
101+
102+
```
103+
localhost:52773/crud/persons/5
104+
```
105+
106+
## How to start coding
107+
This repository is ready to code in VSCode with ObjectScript plugin.
108+
Install [VSCode](https://code.visualstudio.com/) and [ObjectScript](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript) plugin and open the folder in VSCode.
109+
Open /src/cls/PackageSample/ObjectScript.cls class and try to make changes - it will be compiled in running IRIS docker container.
110+
111+
Feel free to delete PackageSample folder and place your ObjectScript classes in a form
112+
/src/cls/Package/Classname.cls
113+
114+
The script in Installer.cls will import everything you place under /src/cls into IRIS.
115+
116+
## What's insde the repo
117+
118+
# Dockerfile
119+
120+
The simplest dockerfile to start IRIS and load ObjectScript from /src/cls folder
121+
Use the related docker-compose.yml to easily setup additional parametes like port number and where you map keys and host folders.
122+
123+
# Dockerfile-zpm
124+
125+
Dockerfile-zpm builds for you a container which contains ZPM package manager client so you are able to install packages from ZPM in this container
126+
127+
# .vscode/settings.json
128+
129+
Settings file to let you immedietly code in VSCode with [VSCode ObjectScript plugin](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript))
130+
131+
# .vscode/launch.json
132+
Config file if you want to debug with VSCode ObjectScript

docker-compose.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3.6'
2+
services:
3+
iris:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
restart: always
8+
ports:
9+
- 51773
10+
- 52773:52773
11+
- 53773
12+
volumes:
13+
- ~/iris.key:/usr/irissys/mgr/iris.key
14+
- ./:/irisdev/app

irissession.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
iris start $ISC_PACKAGE_INSTANCENAME quietly
4+
5+
cat << EOF | iris session $ISC_PACKAGE_INSTANCENAME -U %SYS
6+
do ##class(%SYSTEM.Process).CurrentDirectory("$PWD")
7+
$@
8+
if '\$Get(sc) do ##class(%SYSTEM.Process).Terminate(, 1)
9+
zn "%SYS"
10+
do ##class(SYS.Container).QuiesceForBundling()
11+
Do ##class(Security.Users).UnExpireUserPasswords("*")
12+
halt
13+
EOF
14+
15+
exit=$?
16+
17+
iris stop $ISC_PACKAGE_INSTANCENAME quietly
18+
19+
exit $exit

module.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Document name="rest-template.ZPM">
4+
<Module>
5+
<Name>rest-template</Name>
6+
<Version>1.0.5</Version>
7+
<Packaging>module</Packaging>
8+
<SourcesRoot>src</SourcesRoot>
9+
<Resource Name="Sample.PKG"/>
10+
11+
<CSPApplication
12+
Url="/crud"
13+
Recurse="1"
14+
SourcePath="/web"
15+
DeployPath="{$cspdir}/crud"
16+
MatchRoles=":{$dbrole}"
17+
PasswordAuthEnabled="1"
18+
UnauthenticatedEnabled="0"
19+
DispatchClass="Sample.PersonREST"
20+
ServeFiles="1"
21+
CookiePath="/crud"
22+
UseCookies="2"
23+
/>
24+
</Module>
25+
26+
</Document>
27+
</Export>

0 commit comments

Comments
 (0)