Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

API試し方メモ

More than 3 years have passed since last update.

方法1 curl

curl http://localhost:3000/internal/v1/users/partner_organizations?parameter_name=something&another=something_else

パラメタのstringは''で囲まなくてok

パラメタを配列として渡したい場合:
例えばids: [1, 2, 3]をパラメタとして渡したい時
curl http://localhost:3000/internal/v1/users/partner_organizations?いids[]=1&ids[]=2&ids[]=3
一つずつ渡さないといけない...


curl: (3) [globbing] bad range specification in column 136

とか出る時
curl --globoff http://localhost:3000/internal/v1/users/partner_organizations\?user_ids\[\]\=1

--globoffとすれば良い

globoffドキュメント

-g/--globoff
              This  option  switches  off  the "URL globbing parser". When you set this option, you can
              specify URLs that contain the letters {}[] without having them being interpreted by  curl
              itself.  Note  that  these  letters  are not normal legal URL contents but they should be
              encoded according to the URI standard.

方法2 rails cでconsoleを起動しrailsのapiを叩くgem HTTPartyを使う

(アプリケーションでHTTParty gemを使っていることを前提とする)
rails cでconsoleを起動、以下で行ける。
パラメタの渡し方がラク。

url = 'http://localhost:3000/internal/v1/users/partner_organizations'
params = {application_token: 'honya', user_id: [24, 13, 14]}
method = :get

a = JSON.parse(HTTParty.send(method, url, { body: params }).body)

cf) JSON.parseってやるとjson(配列形式)にしてくれる

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away