IBM i Global

IBM i 

A space for professionals working with IBM’s integrated OS for Power systems to exchange ideas, ask questions, and share expertise on topics like RPG and COBOL development, application modernization, open source integration, system administration, and business continuity.


#Power


#IBMi
#Power
 View Only
Expand all | Collapse all

Setting headers and cookies when using IWS with SQL

  • 1.  Setting headers and cookies when using IWS with SQL

    Posted Mon October 20, 2025 10:10 AM

    Hello all,

    Is there a way for SQL functions or stored procedures called via a REST service on the IWS to set headers and cookies? Also, is there a way to wrap all headers into an input parameter?

    Many thanks,

    Tim.



    ------------------------------
    Tim Fathers
    ------------------------------


  • 2.  RE: Setting headers and cookies when using IWS with SQL

    Posted Mon October 20, 2025 10:38 AM
    Edited by Paul Nicolay Mon October 20, 2025 10:40 AM

    Yes, you can do this via the Options parameter... see HTTP_GET and HTTP_GET_BLOB - IBM Documentation for more info.

    But I guess I did misunderstand you... it is not calling them, but I guess on returning from an SQL based webservice ?



    ------------------------------
    Paul Nicolay
    ------------------------------



  • 3.  RE: Setting headers and cookies when using IWS with SQL

    Posted Mon October 20, 2025 11:40 AM

    ...yes, I meant when creating a REST web service using IWS with an SQL-type backend. I can see how to pass in request headers, but not how to set the response headers.



    ------------------------------
    Tim Fathers
    ------------------------------



  • 4.  RE: Setting headers and cookies when using IWS with SQL

    Posted Tue October 21, 2025 05:19 AM

    Tim, 

    Are you "wrapping" a SQL Statment or Stored Procedure through IWS and then calling this service outside? 



    ------------------------------
    Marius le Roux theIBMiGuy
    Owner , IBM i Modernization and Integration Consultant
    MLR Consulting
    ------------------------------



  • 5.  RE: Setting headers and cookies when using IWS with SQL

    Posted Tue October 21, 2025 05:50 AM

    We currently wrap stored procedures with a REST API using an internal framework we wrote years ago, which works very much like the Web Services Server as far as I can tell. One of the shortcomings of our existing framework is that it doesn't pass headers or cookies through and I was wondering if the IWS was able to do that when configured to use an SQL backend. I can see that individual request headers can be passed in but I can't see a way for response headers to be returned. I was also wondering if all request headers can be wrapped and passed in as a JSON structure, without having to specify a parameter for each one.

    We wouldn't be calling SQL statements directly - only via a SP or UDF.

    Tim



    ------------------------------
    Tim Fathers
    ------------------------------



  • 6.  RE: Setting headers and cookies when using IWS with SQL

    Posted Tue October 21, 2025 09:03 AM

    Ok I now follow:  

    On this link, yes it refers to that its possible :https://www.ibm.com/support/pages/node/6173517/ 

    See on point number (2):  
    Specify resource method information panel
    Its specified in the format of case-insensitive name followed by a colon ':' and its value.

    Quote from the help text : HTTP header information: Specify any HTTP headers the resource method will return. Each header must be specified on a separate line. An HTTP header consists of a case-insensitive name followed by a colon ':' and its value.

    Though I do not see a way that you can return this based on a runtime value if you do choose the SQL route - this looks static. in RPGLE though, its just a matter of defining the parameter in an array and mapping that during the Service creation. 

    @Nadir K Amra can perhaps guide or correct my reasoning here. 

    HTH 



    ------------------------------
    Marius le Roux theIBMiGuy
    Owner , IBM i Modernization and Integration Consultant
    MLR Consulting
    ------------------------------



  • 7.  RE: Setting headers and cookies when using IWS with SQL

    Posted Tue October 21, 2025 09:24 AM

    Many thanks for the reply. Yes, I saw that but as it appears to only support static values, it's not very useful unfortunately. I'd like to avoid going down the RPG route if I can help it.

    Tim.



    ------------------------------
    Tim Fathers
    ------------------------------



  • 8.  RE: Setting headers and cookies when using IWS with SQL

    Posted Tue October 21, 2025 01:54 PM

    Its only the first compile that fails that is the most difficult with RPG *joke. 

    but to your original problem, I don't see a way to do that from SQL itself , not even if one wraps a Stored Proc. Could a  great IBM Idea though for enhancement in my opinion. 



    ------------------------------
    Marius le Roux theIBMiGuy
    Owner , IBM i Modernization and Integration Consultant
    MLR Consulting
    ------------------------------



  • 9.  RE: Setting headers and cookies when using IWS with SQL

    Posted Wed October 22, 2025 11:26 AM
    Edited by Nadir K Amra Wed October 22, 2025 11:26 AM

    Hi, on our TODO list to allow the programmatic setting of response HTTP headers in SQL web services.  So right now you cannot do that. 



    ------------------------------
    Nadir K Amra
    ------------------------------



  • 10.  RE: Setting headers and cookies when using IWS with SQL

    Posted Wed October 22, 2025 01:01 PM

    Hi Nadir, thanks for the reply - we'll look out for it in a later release. Being able to have all the request headers wrapped would be great too.

    Tim.



    ------------------------------
    Tim Fathers
    ------------------------------