|
| 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 | + |
| 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 |
0 commit comments