Ruby example of Net::HTTP for GET, POST, PUT, DELETE -
I am trying to learn Ruby for the first time. I have some experience in PHP and PHP, I have created a function such as
function call_api (endpoint, method, arr_parameters = '') {// a curl call} How will I use
call_api ('https://api.com/user','get','param=1&ur=2'); Call_api ('https://api.com/user/1','get'); Call_api ('https://api.com/user/1','post','param=1&pparam=2'); Call_api ('https://api.com/user/1','put','param=1&pparam=2'); Call_api ('https://api.com/user/1','delete'); So far, I have only learned how to make a GET and POST call with Ruby:
conn = Net :: HTTP.new ( API_URL, API_PORT) resppost = conn.post ("/ user", 'param = 1', {}) respget = conn.get ("/ user? Param = 1", {}) But I do not know how to delete and insert. Can someone show sample code to destroy and call with Net :: HTTP objects?
You only name space:
net :: HTTP :: With Put.new (uri) deletion:
net :: http: delete nn (ury) You can do the same with your existing calls:
conn = Net :: HTTP .new (uri) con.get (path) This is equivalent:
net :: HTTP :: Get.new (uri)
Comments
Post a Comment