我想第一次學習Ruby。我有PHP和PHP的一些經驗,我做喜歡用於GET,POST,PUT,DELETE的Net :: HTTP的Ruby示例
function call_api(endpoint,method,arr_parameters='')
{
// do a CURL call
}
一個功能,我會用像
call_api('https://api.com/user','get','param=1¶m=2');
call_api('https://api.com/user/1','get');
call_api('https://api.com/user/1','post','param=1¶m=2');
call_api('https://api.com/user/1','put','param=1¶m=2');
call_api('https://api.com/user/1','delete');
到目前爲止,我只學會了如何做一個GET和POST調用與Ruby像這樣:
conn = Net::HTTP.new(API_URL, API_PORT)
resppost = conn.post("/user", 'param=1', {})
respget = conn.get("/user?param=1",{})
但我不知道如何做刪除和放。有人可以顯示刪除的示例代碼並將調用與Net :: HTTP對象?
有許多非常Ruby的良好HTTP gems,特別是Curb,它是libCurl的一個經過良好測試的包裝器。 https://www.ruby-toolbox.com/categories/http_clients有一個很好的列表,而不是試圖推出自己的,最好是利用其他人完成的工作。 – 2014-10-10 21:39:44
Net :: HTTP設計相當糟糕,在我看來打破了很多Ruby約定。我第二@TheTinMan,並建議使用不同的http客戶端庫,如果你可以 – JKillian 2014-10-10 21:54:59
嘿約翰做我的答案幫助? – Anthony 2014-10-13 17:25:37