The HBase rest service needs to be started on the server before you start the HBase rest server
Bin/hbase Rest Start-p <port>
Start the HBase service in the background
bin/hbase-daemon.sh Start Rest-p <port>
Stop Service
bin/hbase-daemon.sh Stop Rest
Port defaults to 8080 without port
The Python code that uses the requests module to access the rest interface is as follows, where comments are accessed using the Curl command:
BaseURL = "http://192.168.119.128:8080"; #获取表table2中rowkey为liu的行 response = Requests.get (baseurl+ '/table2/liu ', headers={"Accept": "Application/json"}) ' ' Equivalent to Curl-h ' Accept:application/json ' http://192.168.119.128:8080/table2/liu ' print response. JSON () #返回的字段名称和值为base64编码的, need to decrypt view print base64.b64decode (U ' bw9ibgllog== ') #查看集群状态 response = requests.ge T (baseurl+ '/status/cluster ', headers={"Accept": "Application/json"}) ' Equals Curl-h ' Accept:application/js On "Http://192.168.119.128:8080/status/cluster" Print Response.json () #查看集群版本 response = Request S.get (baseurl+ '/version/cluster ', headers={"Accept": "Application/json"}) ' Equals Curl-h ' accept:appl Ication/json "Http://192.168.119.128:8080/status/cluster" Print Response.json () #获得表list response = R Equests.get (baseurl+ '/', headers={"Accept": "Application/json"}) ' is equivalent to curl -H "Accept:application/json" http://192.168.119.128:8080/"Print Response.json () #table2中添加一行数据rowk EY is moblie,xml field name and data base64 encoded Rdata= ' <?xml version= ' 1.0 ' encoding= ' UTF-8 ' standalone= ' yes '?><cellset> <row key= "bw9ibgllog==" ><cell column= "bw9ibgllog==" >bgl1emhvdwxvbmcy</cell></ro w></
Cellset> ' response = requests.put (baseurl+ '/table2/moblie ', data=rdata,headers = {' Content-type ': ' Text/xml '}) Print response #curl-vi-x put-h "Accept:text/xml"-H "content-type:text/xml"-d ' <?xml version= "1.0" en coding= "UTF-8" standalone= "yes"? ><cellset><row key= "BW9 ibgllog==" ><cell column= "bW9ibGllOg==" >bGl1emhvdWxvbmcy</Cell></Row></CellSet> ' Http://192.168.119.128:8080/table2/moblie ' # Add Table Users rdata= ' <?xml version= "1.0" encoding= "UTF-8"? ><tableschema name= "Users" ><columnschema name= " CF "/></tableschema> ' response = Requests.posT (baseurl+ '/users/schema ', data=rdata,headers = {' Content-type ': ' Text/xml '}) print response #curl-vi-x post-h "Accept:text/xml"-H "content-type:text/xml"-d ' <?xml version= "1.0" encoding= "UTF-8"? ><tableschema name= " Users "><columnschema name=" CF "/></tableschema> '" Http://192.168.119.128:8080/users/schema "#删除 Table Users response = Requests.delete (baseurl+ '/users/schema ') print response #curl-vi-x delete-h "Accept:tex T/xml "" Http://192.168.119.128:8080/users/schema "
For more information, please refer to
Http://hbase.apache.org/book.html#_rest
Extended Curl Parameter meaning
-x/--request [get| Post| Put| Delete| ...] Using the specified HTTP method to send out an HTTP request
-h/--header set the header in the request
-i/--include shows response's header
-d/--data Setting HTTP Parameters
-v/--verbose more messages
-u/--user user account, password
-b/--cookie Cookies
HBase access methods include the following:
1. Native Java API: The most conventional and efficient way to access;
2, hbase shell:hbase command line tool, the simplest interface, suitable for hbase management use;
3, Thrift Gateway: The use of Thrift serialization technology, support C++,php,python and other languages, suitable for other heterogeneous systems online access hbase table data;
4, rest Gateway: Support the rest-style HTTP API to access HBase, lifting the language restrictions;
5. MapReduce: Processing hbase data directly using mapreduce operations;
6. Use pig/hive to process hbase data.