1. WebHDFS User Guide

The following examples use the curl command tool to access HDFS via WebHDFS REST API.

  • To read a file (for example: /foo/bar):

    curl -i -L "http://$<Host_Name>:$<Port>/webhdfs/v1/foo/bar?op=OPEN"
        
  • To list a directory (for example: /foo):

    curl -i "http://$<Host_Name>:$<Port>/webhdfs/v1/foo/?op=LISTSTATUS"
        
  • To list the status of a file (for example: /foo/bar) or a directory:

    curl -i "http://$<Host_Name>:$<Port>/webhdfs/v1/foo/bar?op=GETFILESTATUS"
        
  • To write a file into a /foo/new file:

    curl -i -X PUT -L "http://$<Host_Name>:$<Port>/webhdfs/v1/foo/newFile?op=CREATE" -T newFile
        
  • To rename the /foo/bar file to /foo/bar3:

    curl -i -X PUT "http://$<Host_Name>:$<Port>/webhdfs/v1/foo/bar?op=RENAME&destination=/foo/bar2"
        
  • Make new directory /foo2:

    curl -i -X PUT "http://$<Host_Name>:$<Port>/webhdfs/v1/foo2?op=MKDIRS&permission=711"