Calling Web Services via Curl

From Fusion Registry Wiki
Jump to navigation Jump to search

Rather than using the Graphical User Interface, the Registry can perform operations by calling its Web Services. Examples of these are the Data Validation and Data Transformation Web Services. These can be invoked by a tool such as Postman, but this page aims to give some guidance on using the UNIX tool "curl" to invoke these Web Services.

Example Use of Curl

The following shows an example use of curl to the Fusion Metadata Registry.

  curl -X POST 
    --header "Content-Type:application/text" 
    --header "Accept: application/vnd.sdmx.structurespecificdata+xml;version=2.1" 
    --header "Structure:urn:sdmx:org.sdmx.infomodel.datastructure.Dataflow=OECD:DF_BATIS_EBOPS2010(1.0)" 
    --data-binary "@My Input File.csv" 
    http://localhost:8080/FusionRegistry/ws/public/data/transform 
    > Generated.xml

The above specifies:

  • curl is performing a POST operation
  • The Header parameter of "Content-Type" is set to application/text
  • The Header parameter of "Accept" is set to output in SDMX-ML Structure Specific 2.1 form
  • The input file is an SDMX-CSV input file called "My Input File.csv"
  • The Registry is accessible at: http://localhost:8080/FusionRegistry and the transform Web Service is : /ws/public/data/transform
  • The output is beng redirected into the file "Generated.xml"


Use of data-binary

It is highly recommended to specify your file with the "--data-binary" option. Curl's -d option will strip out newline characters so is fine when validating / transforming XML but not for when you are processing CSV or Microsoft Excel files.

Combining UNIX commands

Since CURL is a standard UNIX command it can be combined with other commands to perform more complicated tasks and is especially useful in performing batch operations.

A simple example of this is using CAT as the input can be performed by stating the input is "@-". An example follows showing how "cat"ing a SDMX JSON file and piping the output into the CURL command to submit the structure file to the Registry. This example also shows passing in a userid and password:

  cat SimpleCodelist.json |
  curl -X POST 
    --user root:password 
    --header "Content-Type: application/json" 
    --data-binary @- 
     http://localhost:8080/FusionRegistry/ws/secure/sdmxapi/rest