I am trying to get an HTTP API from existing server - following below article
https://docs.remotingsdk.com/Servers/Concepts/HttpAPI/SampleDelphi/
issues I am facing are
Application contains lot of custom objects (not remobject’s custom object) which has been passed from client to server in binary format. I am not sure if same can be achieved using HTTP API
Sample function :
[ROServiceMethod]
[ROCustom(‘HttpApiPath’,‘rolePlayers’)]
[ROCustom(‘HttpApiMethod’,‘POST’)]
[ROCustom(‘HttpApiResult’,‘201’)]
function MyGetFunction(const CallInfo: stCallInfo;
[ROCustom(‘HttpApiQueryParameter’,‘1’)] const sRoleName: string;
[ROCustom(‘HttpApiQueryParameter’,‘1’)] const sStartingWith: string;
[ROCustom(‘HttpApiQueryParameter’,‘1’)] const bTemplates: Boolean;
const Query: TMyOwnClassObject;
[ROCustom(‘HttpApiQueryParameter’,‘1’)] const iParentID: Integer): Boolean;
In above example , TMyOwnClassObject is a class in code which has been shared between client and server and it’s object is passed in binary format from client to server and vice versa.
existing business logic is written using above custom classes. just want to understand if there is any workaround for this problem which can be implemented with least resources ?
I want to pass 2 parameter in request body but it seems only one parameter is allowed as request body. for above function , I think two parameter must by part of request body but showing only CallInfo
Please help me with this
EvgenyK
(Evgeny Karpov)
November 28, 2019, 10:21am
2
Hi,
you can pass data in binary format as Binary
type.
[ROServiceMethod]
[ROCustom('HttpApiPath','rolePlayers')]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiResult','201')]
function MyGetFunction(const CallInfo: Binary;
[ROCustom('HttpApiQueryParameter','1')] const sRoleName: string;
[ROCustom('HttpApiQueryParameter','1')] const sStartingWith: string;
[ROCustom('HttpApiQueryParameter','1')] const bTemplates: Boolean;
const Query: Binary;
[ROCustom('HttpApiQueryParameter','1')] const iParentID: Integer): Boolean;
swagger editor will see this method as
swagger: '2.0'
info:
title: NewProjectLibrary
version: 1.0.0
basePath: /api
consumes:
- application/json
produces:
- application/json
paths:
/rolePlayers:
post:
parameters:
- name: sRoleName
in: query
type: string
- name: sStartingWith
in: query
type: string
- name: bTemplates
in: query
type: boolean
- name: iParentID
in: query
type: integer
format: int32
- name: NewProjectServiceMyGetFunctionRequest
in: body
schema:
$ref: '#/definitions/NewProjectServiceMyGetFunctionRequest'
responses:
'201':
description: The method call completed successfully
schema:
type: boolean
'400':
description: Bad Request
'500':
description: Internal Server Error
definitions:
NewProjectServiceMyGetFunctionRequest:
type: object
properties:
CallInfo:
type: string
format: binary
Query:
type: string
format: binary
if you execute curl request like
curl -verbose -X POST “http://localhost:8099/api/rolePlayers?sRoleName=RoleName&sStartingWith=StartingWith&iParentID=100 ” -H “accept: application/json” -H “content-type: application/json” -d “{ "CallInfo": "c29tZSBjYWxsaW5mbyB2YWx1ZQ==", "Query": "c29tZSBxdWVyeSB2YWx1ZQ=="}”
on server-side, you will see