Jiwa-stateful  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Jiwa-stateful

Postby SBarnes » Fri Jun 30, 2017 1:05 pm

Hi Mike

to make the API operate with state you use the following code:

Code: Select all
client.Headers.Add("jiwa-stateful", "true");


is there a way to make the API operate in a mixed mode i.e by doing something like

Code: Select all
client.Headers.Remove("jiwa-stateful");


or do you need to log off and log back on again, what I am asking is is the header checked each time and behaviour determined at the time of the call or is it held somehow to the session?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1620
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Jiwa-stateful  Topic is solved

Postby Mike.Sheen » Fri Jun 30, 2017 1:09 pm

Hi Stuart,

You can remove them at any time, and the next call won't include them.

Here's an example from our unit tests which use the ServiceStack client to do exactly that:
Code: Select all
[Test]
public void Carriers_Stateful_Create_Save()
{
   client.Headers.Add("jiwa-stateful", "true");

   // Try before logging on to make sure we get a 401
   var carrierPOSTRequest = new CarrierPOSTRequest { CarrierName = Guid.NewGuid().ToString(), Enabled = false };
   Carrier carriersPOSTResponse;
   var ex = Assert.Throws<ServiceStack.WebServiceException>(() => carriersPOSTResponse = client.Post(carrierPOSTRequest));
   Assert.AreEqual(401, ex.StatusCode);

   Logon();

   // POST: /Carriers
   carrierPOSTRequest = new CarrierPOSTRequest { CarrierName = Guid.NewGuid().ToString(), Enabled = false };
   carriersPOSTResponse = client.Post(carrierPOSTRequest);

   // Check the response has the same name as the request
   Assert.AreEqual(carriersPOSTResponse.CarrierName, carrierPOSTRequest.CarrierName);

   // Now do a non-stateful read to make sure it's not present yet
   // GET: /Carriers/{CarrierID}
   client.Headers.Remove("jiwa-stateful");
   var carrierGETRequest = new CarrierGETRequest() { CarrierID = carriersPOSTResponse.CarrierID };
   // We expect a 404 when reading
   Carrier carrierGETResponse;
   ex = Assert.Throws<ServiceStack.WebServiceException>(() => carrierGETResponse = client.Get(carrierGETRequest));
   Assert.AreEqual(404, ex.StatusCode);

   // Add back the stateful header
   client.Headers.Add("jiwa-stateful", "true");

   // GET: /Carriers/{CarrierID}/Save
   var carrierSAVERequest = new CarrierSAVERequest() { CarrierID = carriersPOSTResponse.CarrierID };
   var carrierSAVEResponse = client.Get(carrierSAVERequest);

   // GET: /Carriers/{CarrierID}
   carrierGETRequest = new CarrierGETRequest() { CarrierID = carrierSAVEResponse.CarrierID };
   carrierGETResponse = client.Get(carrierGETRequest);

   // Check the Name is what we expect
   Assert.AreEqual(carrierGETResponse.CarrierName, carrierPOSTRequest.CarrierName);
}


EDIT: To answer your question, the ServiceStack client will include them for every request once set, until removed.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Jiwa-stateful

Postby SBarnes » Fri Jun 30, 2017 1:23 pm

Cheers
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1620
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to REST API

Who is online

Users browsing this forum: No registered users and 3 guests