Skip to content

06 Working with json and xml

POST JSON > API > XML > DB

HTTP
1
2
3
4
curl '{{host}}/api/srs/333-test/run.json' \
  -H 'Content-Type: application/json' \
  --user 'api:{{token}}' \
  --data-raw '{"xmldatainput":"{\"test\":\"[email protected]\" }","operation":"post"}'

GET DB >XML > API > JSON

HTTP
1
2
3
4
curl '{{host}}/api/srs/333-test/run.json' \
  -H 'Content-Type: application/json' \
  --user 'api:{{token}}' \
  --data-raw '{"operation":"get"}'

Example

SRS

XML
<srs title="test">
  <def>
    <itm model="param" name="operation"/>
    <itm model="param" name="xmldatainput" type="json-xml"/>
    <itm model="column" name="xmldata" type="tjson"/>
    <itm name="post">
      if @operation='post'
        insert into testxml (xmldata)  values (@xmldatainput)
    </itm>
    <itm name="get">  
      if @operation='get'
            select * from testxml
    </itm>
  </def>
</srs>

DB

SQL
CREATE TABLE [dbo].[testxml](
    [id] [uniqueidentifier] NOT NULL,
    [xmldata] [xml] NULL,
 CONSTRAINT [PK_testxml] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[testxml] ADD  CONSTRAINT [DF_testxml_id]  DEFAULT (newid()) FOR [id]