Atozed Forums
Intraweb for Rest API POST - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Intraweb for Rest API POST (/thread-1402.html)

Pages: 1 2


Intraweb for Rest API POST - ShaneStump - 11-25-2019

Howdy All!

I am exposing my web reservation system to Viator and I need to implement a REST api around my internal classes.

I have written content handlers for each REST api call with the appropriate path.

I am using Advanced REST Client to test my application running as a service.

I put my URL and method to POST. I copy my XML for processing into the Body of the request and issue it.

From within the C++ Builder IDE, I set and get a breakpoint on handler's Execute().

I can't see anywhere in the THttpRequest object where the content passed in is.

How do I read / fetch it from within my event?

Thanks in advance,

Shane


RE: Intraweb for Rest API POST - kudzu - 11-25-2019

Content Handlers.... are you using them already?

function xxx.Execute(aRequest: THttpRequest; aReply: THttpReply;
const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean;

if aRequest.CommandType = hcPost then begin
with TStreamReader.Create(aRequest.PostStream) do try
xJSON := ReadToEnd;
finally Free; end;


RE: Intraweb for Rest API POST - ShaneStump - 11-25-2019

(11-25-2019, 08:43 PM)kudzu Wrote: Content Handlers.... are you using them already?

function xxx.Execute(aRequest: THttpRequest; aReply: THttpReply;
  const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean;

  if aRequest.CommandType = hcPost then begin
    with TStreamReader.Create(aRequest.PostStream) do try
      xJSON := ReadToEnd;
    finally Free; end;
Howdy Big K!

Thanks for answering.

I have using a TContentBase based handler and when my REST api handler's Execute() is called,  I am trying to figure out how to extract the content from the body of the request.

The aRequest parameter does NOT have a PostStream parameter. I can't see how to retrieve the XML data I sent in the body of the initial request.

What am I missing?

Thanks,

Shane


RE: Intraweb for Rest API POST - Jose Nilton Pace - 11-25-2019

Hi Shane, look this demo: https://github.com/Atozed/IntraWeb/blob/master/XIV/Delphi/PostDataDemo/IW.Content.XML.pas


RE: Intraweb for Rest API POST - ShaneStump - 11-25-2019

Howdy Jose!

I am NOT attaching an XML file. I am putting it into the body of the request.

The Request->Files->Count is zero any how (I had already checked that).

I have tried several things with Advanced Rest Client and when I look at the RawHeaders property of THttpRequest, the last one lists as "content-length: 2500".

I can't figure out how to get the content. The content is an XML stream like below:

<?xml version="1.0" encoding="UTF-8"?>
<BookingRequest xmlns="http://toursgds.com/api/01">
<ApiKey>{AD7276FB-9F98-4495-BB1A-E24E99B82E06}</ApiKey>
<ResellerId>12345</ResellerId>
<SupplierId>67890</SupplierId>
<ExternalReference>10051374722992645</ExternalReference>
<Timestamp>2019-11-13T12:43:44.014Z</Timestamp>
<Parameter>
<Name>CompanyID</Name>
<Value>75</Value>
</Parameter>
<Parameter>
<Name>CustomerID</Name>
<Value>19229</Value>
</Parameter>
<Extension>
<any/>
</Extension>
<BookingReference>000000028</BookingReference>
<TravelDate>2019-11-25</TravelDate>
<SupplierProductCode>HIC</SupplierProductCode>
<Location>Kingston, CA</Location>
<TourOptions>
<SupplierOptionCode>HIC</SupplierOptionCode>
<SupplierOptionName>Heart of the Islands Cruise</SupplierOptionName>
<TourDepartureTime>12:30:00</TourDepartureTime>
<TourDuration>PT3H</TourDuration>
<Option>
<Name>Location</Name>
<Value>CW</Value>
</Option>
<Option>
<Name>Resource</Name>
<Value>IQ</Value>
</Option></TourOptions>
<CurrencyCode>USA</CurrencyCode>
<Amount>250.00</Amount>
<Traveller>
<TravellerIdentifier>1</TravellerIdentifier>
<TravellerTitle>Mr</TravellerTitle>
<GivenName>Shane</GivenName>
<Surname>Stump</Surname>
<AgeBand>ADULT</AgeBand>
<LeadTraveller>true</LeadTraveller>
</Traveller>
<Traveller>
<TravellerIdentifier>2</TravellerIdentifier>
<TravellerTitle>Mrs</TravellerTitle>
<GivenName>Sandi</GivenName>
<Surname>Stump</Surname>
<AgeBand>ADULT</AgeBand>
<LeadTraveller>false</LeadTraveller>
</Traveller>
<Traveller>
<TravellerIdentifier>3</TravellerIdentifier>
<TravellerTitle>Miss</TravellerTitle>
<GivenName>Cassie</GivenName>
<Surname>Stump</Surname>
<AgeBand>ADULT</AgeBand>
<LeadTraveller>false</LeadTraveller>
</Traveller>
<TravellerMix>
<Adult>3</Adult>
<Child>0</Child>
<Youth>0</Youth>
<Infant>0</Infant>
<Senior>0</Senior>
<Total>3</Total>
</TravellerMix>
<SpecialRequirement>Special Requirement</SpecialRequirement>
<SupplierNote>Customer notes</SupplierNote>
<AdditionalRemarks>
<Remark>Additional remarks #1.</Remark>
<Remark>Additional remarks #2.</Remark>
</AdditionalRemarks>
<ContactDetail>
<ContactType>MOBILE</ContactType>
<ContactName>Shane Stump </ContactName>
<ContactValue>US+1 123-456-7890</ContactValue>
</ContactDetail>
<ContactEmail>MSG-8b17fa92-7b35-4fdb-9f18-f8a69252e019+BR-999999999@expmessaging.tripadvisor.com</ContactEmail>
<AvailabilityHoldReference></AvailabilityHoldReference>
</BookingRequest>

The stream is 2500 bytes.

How do I get it?

Thanks in advance,

Shane


RE: Intraweb for Rest API POST - ShaneStump - 11-26-2019

Good morning,

I sure hope I get an answer before long as I have a conference call with my board in 4 hours and I have to give a timeframe on this.

I just need to know if I can do this in IW or if I need to look for a different solution.

Thanks,

Shane


RE: Intraweb for Rest API POST - Jose Nilton Pace - 11-26-2019

Hi Shane, this picture [https://github.com/Atozed/IntraWeb/blob/master/XIV/Delphi/PostDataDemo/How%20to%20simulate%20a%20request%20using%20Firefox%20Poster%20addon.png] show how you can test the demo. The demo is not attached, is sent in body, IW get the body.


RE: Intraweb for Rest API POST - ShaneStump - 11-26-2019

Thanks.

I will have a further look after my board gives me a colonoscopy this morning?.

All the best,

Shane


RE: Intraweb for Rest API POST - ShaneStump - 11-26-2019

Jose,

It is working in Delphi example but not in my C++ application. The handler gets executed, but the content isn't there.

I will need to see if there is anything else changed or if the is a compatibility with C++ Builder.

Thanks,

Shane

Howdy All!

I figured out the DIFFERENCE in the example / my code!

In the ServerController, need to add the following line to my ConfigBase event:

RegisterContentType(L"application/xml");

Now it works!

Thanks for the help,

Shane


RE: Intraweb for Rest API POST - kudzu - 11-26-2019

(11-25-2019, 08:58 PM)ShaneStump Wrote:
(11-25-2019, 08:43 PM)kudzu Wrote: Content Handlers.... are you using them already?

function xxx.Execute(aRequest: THttpRequest; aReply: THttpReply;
  const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean;

  if aRequest.CommandType = hcPost then begin
    with TStreamReader.Create(aRequest.PostStream) do try
      xJSON := ReadToEnd;
    finally Free; end;
Howdy Big K!

Thanks for answering.

I have using a TContentBase based handler and when my REST api handler's Execute() is called,  I am trying to figure out how to extract the content from the body of the request.

The aRequest parameter does NOT have a PostStream parameter. I can't see how to retrieve the XML data I sent in the body of the initial request.

What am I missing?

Thanks,

Shane

Sorry that section of code I pulled was from Indy directly although inside of IntraWeb code.

For IntraWeb it does add it to the file list as you were already looking at. I will ask Alexandre to take a look and respond though as I know in some cases you have to take additional steps for certain types of contents.