Skip to content

Call Web Services using curl

curl is a powerful command line tool for calling HTTP services and is generally available on Linux and Windows platforms.

A full description of it's capabilities is beyond the scope of this guide, but instead here's a few pointers of how it can be used with the FMR REST API.

POST submissions

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