Webservice Request/Response Validation
Description
The LogicNets WebService Framework (WSF) offers tools that allow you to validate the requests and responses of inbound web service calls based on an Open API-based specification (https://www.openapis.org/) you create. You can write these specifications with online tools like Swagger (https://swagger.io/) and upload them to your Web Service project documents folder with names like api.yaml or api.json.
Used With: WebService Framework
Details
Users with the role openapi in their WSF project can download the specification at https://[host/company]/WSFExample/openapi/spec.
You can also access an interactive user interface at https://[host/company]/WSFExample/openapi/apidoc.
You can validate the input request and the generated output response against the specification by passing a special header with the request:
- LN-INFO-REQUEST: WSF-VALIDATION-REQUEST,WSF-VALIDATION-RESPONSE or
- LN-INFO-REQUEST: WSF-VALIDATION-REQUEST or
- LN-INFO-REQUEST: WSF-VALIDATION-RESPONSE
The system can enforce validation with each request, and you configure this on the General tab in the SystemConfiguration module:
If the request or response is invalid, the system returns a 422 HTTP status code.
Example
Download the example project attached to this topic, import it into your Designer, and publish it. Use the following requests to test:
Valid Requests Using Curl
curl --location 'https://trunk.logicnets.local/logicnets/WSFExample/function_1' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'LN-INFO-REQUEST: WSF-VALIDATION-REQUEST,WSF-VALIDATION-RESPONSE' \
--header 'Cookie: __Secure-pin=3C8A6FC65D5734316F90FE45CFA59AE6FC68D8F42389C76B6600FA14F77DD81D'
Invalid Request Examples Using Curl
curl --location 'https://trunk.logicnets.local/logicnets/WSFExample/function_2' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'LN-INFO-REQUEST: WSF-VALIDATION-REQUEST,WSF-VALIDATION-RESPONSE' \
--header 'Cookie: __Secure-pin=1661B33C417B027BB51D8AC819B7B756CC57B082AEF04563EE692F8AB1EA3B5D'
curl --location 'https://trunk.logicnets.local/logicnets/WSFExample/function_1' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'LN-INFO-REQUEST: WSF-VALIDATION-REQUEST,WSF-VALIDATION-RESPONSE' \
--header 'Cookie: __Secure-pin=8FA00CB8A88607F23BF266393DD0EB7A54333D797968C042B0849D4C2DC041A1' \
--data '{
"answer": "question expected"
}'