Encontrar

記事
· 2025年6月24日 3m read

Exposing a Basic REST API with InterSystems IRIS: Step-by-Step Docker Example

Introduction

InterSystems IRIS allows you to build REST APIs using ObjectScript classes and the %CSP.REST framework. This enables the development of modern services to expose data for web apps, mobile apps, or system integrations.

In this article, you'll learn how to create a basic REST API in InterSystems IRIS, including:

  • A persistent data class
  • A REST class with GET and POST methods
  • A web application to expose the API
  • A full demonstration using Docker

Step 1: Create the data class Demo.Producto

Class Demo.Producto Extends (%Persistent, %JSON.Adaptor) {
  Property Nombre As %String;
  Property Precio As %Numeric(10,2);
}
  • %Persistent allows storing the object in the database.
  • %JSON.Adaptor enables automatic JSON conversion.

Step 2: Create the REST class Demo.ProductoAPI

Class Demo.ProductoAPI Extends %CSP.REST {

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ] {
  <Routes>
    <Route Url="/producto" Method="GET" Call="Listar"/>
    <Route Url="/producto" Method="POST" Call="Crear"/>
  </Routes>
}

ClassMethod Listar() As %Status
{
   Try {
    Set productos = []
    &sql(DECLARE C1 CURSOR FOR SELECT ID, Nombre, Precio FROM Demo.Producto)
    &sql(OPEN C1)
    While (SQLCODE=0) {
      &sql(FETCH C1 INTO :id, :nombre, :precio)
      Quit:SQLCODE'=0
      Do productos.%Push({"ID": (id), "Nombre": (nombre), "Precio": (precio)})
    }

    Do ##class(%REST.Impl).%SetContentType("application/json")
    Do ##class(%REST.Impl).%SetStatusCode("200")
    Write productos.%ToJSON()
    } Catch (ex) {
        Do ##class(%REST.Impl).%SetStatusCode("400")
       Write ex.DisplayString()
    }
  Quit $$$OK
}

ClassMethod Crear() As %Status
{
  Try {
    set dynamicBody = {}.%FromJSON(%request.Content)
    Set prod = ##class(Demo.Producto).%New()
    Set prod.Nombre = dynamicBody.%Get("Nombre")
    Set prod.Precio = dynamicBody.%Get("Precio")
    Do prod.%Save()

    Do ##class(%REST.Impl).%SetContentType("application/json")
    Do ##class(%REST.Impl).%SetStatusCode("200")
    Write prod.%JSONExport()
    } Catch (ex) {
        Do ##class(%REST.Impl).%SetStatusCode("400")
       Write ex.DisplayString()
    }
    Quit $$$OK
}

}

Step 3: Create a Web Application

From the Management Portal:

  1. Go to System Administration > Security > Applications > Web Applications
  2. Create a new application:
    • URL: /api/productos
    • Namespace: USER
    • Class: Demo.ProductoAPI
    • Enable REST and anonymous access for testing

http://localhost:52773/csp/sys/%25CSP.Portal.Home.zen  User=SuperUser Pass=SYS

Add Developer Application Functions


Step 4: Docker demonstration

Project structure

apirest-demo/
├── Dockerfile
├── iris.script
└── cls/
    ├── Demo.Producto.cls
    └── Demo.ProductoAPI.cls

Dockerfile

FROM intersystemsdc/iris-community:latest

COPY cls /irisdev/app/cls
COPY iris.script /irisdev/app/iris.script

RUN iris start IRIS \
 && iris session IRIS < /irisdev/app/iris.script \
 && iris stop IRIS quietly

Build and run the container

cd apirest-demo
docker build -t iris-apirest-demo .
docker run -d --name iris-api -p 52773:52773 -p 1972:1972 iris-apirest-demo

Testing with Postman or curl

GET products

curl http://localhost:52773/api/productos/producto

POST product

curl -X POST http://localhost:52773/api/productos/producto \
  -H "Content-Type: application/json" \
  -d '{"Nombre":"Cafe","Precio":2500}'

to download the example code https://github.com/MarcoBahamondes/apirest-demo

git clone https://github.com/MarcoBahamondes/apirest-demo
3 Comments
ディスカッション (3)3
続けるにはログインするか新規登録を行ってください
ディスカッション (0)2
続けるにはログインするか新規登録を行ってください
質問
· 2025年6月24日

Using CodeTidy in my GitHub automated workflow for linting ObjsectScript code

I installed and configure CodeTidy in my local development environment, without InterSystems source-control (git-source-control) and only git for source control.

I would like to use only CodeTidy to stablish an automated  Linting and Code Style Validation for InterSystems ObjectScript code triggered by GitHub Actions.

 

Could you shed some light on how to accomplish that?

1件の新着コメント
ディスカッション (4)5
続けるにはログインするか新規登録を行ってください
記事
· 2025年6月24日 3m read

Celebrating a Lifelong Contributor of the Developer Community

Among the many voices that shape the InterSystems Developer Community, some stand out not only for their knowledge but for their consistency, curiosity, and passion. One of those voices belongs to @Dmitry Maslennikov, a long-time member whose experience spans nearly two decades and who continues to innovate and inspire developers around the globe.

🤩 Let's take a look at Dmitry’s deep-rooted journey with InterSystems and his lasting impact on our Community...

Dmitry's story with InterSystems began in March 2007, when he landed his first programming job. Since then, his professional journey has taken him through several companies, cities, and even countries, but his connection with InterSystems technologies has remained a constant. Over the years, Dmitry has become a seasoned expert in Caché and IRIS, contributing to mission-critical projects and large-scale system architectures.

One of Dmitry’s most memorable milestones involved ensuring performance stability for a high-demand application used by 3,000 concurrent users. Tasked with optimizing speed and responsiveness despite massive data volumes and rapid growth, Dmitry dove deep into performance tuning and architectural design. More recently, he was part of an ambitious project migrating a complex monolithic system to AWS - an effort that involved dissecting functionality into scalable services while managing a unified data layer. Navigating challenges like cross-server coordination and subsystem integration, Dmitry gained invaluable experience in cloud-native transformation.

However, not all learning moments came from planned development work. Dmitry recalls a nerve-wracking incident when he accidentally deleted a crucial global from a production system. The pressure was high, but the experience became a turning point, teaching him the critical skills of backup handling and journal-based recovery.

Dmitry’s relationship with the Developer Community started even before the official Community platform was created. He wrote blog posts and actively participated in Google Groups before finally joining the InterSystems Developer Community at its launch in 2015.

Over time, Dmitry's involvement expanded beyond discussion threads. He has embraced new initiatives, such as Open Exchange, where he shares his projects and participates in community contests. The Ideas Portal has also become a creative playground where Dmitry both draws inspiration and contributes fresh ideas for future development.

His advice for newcomers?

Never stop learning. Explore different ideas and implement them regardless of the technology. The broader your understanding of various approaches is, the better you'll become at solving problems.

Today, Dmitry is driven by a mission: to make InterSystems IRIS more accessible by building projects in multiple programming languages and extending its reach across different development communities. This passion even spills into his free time, where adapting open-source projects to work with IRIS is not just a task, but a genuine hobby.

We’re grateful for Dmitry’s ongoing commitment to the Developer Community. His journey is a testament to persistence, growth, and the boundless potential of shared knowledge. Here's to Dmitry - a true champion of the Community and a builder of bridges across technologies and time zones.

👏 Let's all thank Dmitry for his invaluable contributions and continued inspiration!

12 Comments
ディスカッション (12)5
続けるにはログインするか新規登録を行ってください
質問
· 2025年6月24日

Using %Net.WebSocket.Client

Hi Guys,

I'm trying to use %Net.WebSocket.Client to collect data from a sever,

 

 

and part of that I needed to implement Two classes (SX3.Production.HTTP.AdvCredenials  & SX3.Production.HTTP.AdvListener) as below for the purpose of Credentials & EventListener properties,   

 

Class SX3.Production.HTTP.AdvCredenials Extends %Net.WebSocket.ICredentials
{

Method GetPassword() As %String
{
""
}

Method GetUsername() As %String
{
""
}

Method GetSSLConfiguration() As %String
{
"MySSL"
}

}

Class SX3.Production.HTTP.AdvListener Extends %Net.WebSocket.IEventListener
{

Method OnMessage(pContent As %Stream.Object)
{
^data("message")=pContent.Read()
}

}

and here where I'm using the WebSocket Client. 

I never used  WebSocket Client before neither implementing such classes above for the two properties and I would like to know if below code is the right way to then assign  WebSoc.Credentials, WebSoc.EventListener and to make the call of WebSoc.URL ? 

ClassMethod GetAdvData(Gateway As %String = "", Token) As %String
{
Quit:Gateway="" 1
Set:Gateway[":" Gateway=$TR(Gateway,": ")
Set Found=0
        BleMac="DC:0D:30:00:07:25",GatewayMac="CC:1B:E0:E2:52:D4"  // this for testing
Set WebSoc=##class(%Net.WebSocket.Client).%New()
Set WebSoc.Credentials="SX3.Production.HTTP.AdvCredenials"
Set WebSoc.EventListener="SX3.Production.HTTP.AdvListener"
Set WebSocURL="https://domain3wGT.com/api/gap/nodes?filter_mac="_BleMac_"&filter_rssi=-75&mac="_GatewayMac_"&active=1&event=1&chip=1&access_token="_Token
WebSoc.URL=WebSocURL
Quit 1
}

 

 

Thanks

7 Comments
ディスカッション (7)3
続けるにはログインするか新規登録を行ってください