In my Rails 5 API project I am consuming SOAP services. With the use of the Savon gem, version 2, I parse the response from any SOAP web service to JSON format.
In my Rails project I am creating a facade for multiple SOAP services. Let's say 4 SOAP services that have 90% similar response format/structure. I would like my facade to be accepting and sending out the information from the services in JSON API format.
I found some solutions, but not an ideal and effective one:
- Parsing the JSON/SOAP response from the SOAP service into models/objects, and then outputting this to JSON API through existing libraries (e.g. jsonapi-resources gem)
- Building a serializer from scratch within Rails
- Use an ESB
The first option seems to be overkill and error prone.
The second option seems to be a very time consuming project, and it'll also be prone to a lot of errors if I have to do this by myself in a short amount of time.
The third option is a no go due to budget.
So my question is, do there exist tools out there that can assist me? I have been doing a great deal of research, but have not been able to find anything that seems to be a solution to my problem or fulfilling my needs.
Solution so far
I found it most pragmatic to go with option 1. I am doing something similar to the following:
# app/controllers/api/v1/some_resources_controller.rb
...
# Retrieve response from service
response = fetch_resources_from_service(query)
# Pick out the values from the response that we want to output
resource_params = strip_response(reponse, whitelist: [:id, :title, :date, ...]
# Create a model object from these stripped/whitelisted params
resource = Api::V1::SomeResource.new(resource_params)
# Render in JSON API format (with active_model_serializer)
render json: resource, adapter: :jsonapi, serializer: Api::V1::SomeResourceSerializer