Tutorial Guide > REST Tutorial > Adding a Custom Parameter in an HTTP Header for a REST Request to a Published Method
 
Adding a Custom Parameter in an HTTP Header for a REST Request to a Published Method
For better security, you can add a custom parameter in an HTTP header for a REST request. This requires the ability to read the header of an incoming REST request in a TDV script. To read the parameter, you can wrap table or view in a script, or use a hook to read the values.
The following example uses a procedure to return the header property. It uses the TDV GetClientProperty API to get HTTP header properties per request from client.
To add the ability to read HTTP header fields
1. Create a procedure to return the header field. For example:
PROCEDURE readHeader(in param date, out OrderID integer, out OrderDate TIMESTAMP, out contentType VARCHAR(255))
BEGIN
CALL /lib/util/GetClientProperty('Contenttype123', contentType);
SELECT
Orders.OrderID,
Orders.OrderDate
INTO OrderID, OrderDate
FROM /shared/HttpHeader/ds_orders/tutorial/orders Orders
WHERE Orders.OrderDate = param;
END
 
2. Publish the procedure to the Web Service.
3. Create a REST data source with HTTP/JSON Endpoint URLs. For example, the value of the Base URL is:
http://DVBU-VDI-008:9400/json/HttpHeader004/readHeader?
 
4. Scroll down the Basic tab to the Operations section.
5. Add a GET operation to the REST resource.
6. Add Header/Body Parameters. The Param Name must be same as the HTTP Header name, which is the first parameter of GetClientProperty. HTTP header names are case-insensitive.
7. Type Contenttype123 for the Parameter name.
8. Specify HTTP Header for the Location.
9. Save the data source.
10. Open the operation.
11. Execute the GET operation.
12. Input the parameters.
13. Review the results.
14. Save and close.
15. Use your client applications to access the REST service get operation that you have defined. Verify that the results are what you expect.