LoginSignup
6
6

More than 3 years have passed since last update.

curl コマンドで Qiita API を試す方法

Last updated at Posted at 2017-01-26

やること

  • curl コマンドで Qiita API を叩いてみる

Qiita API を実行するトークンを発行する

curl で Qiita API を叩いてみる

  • curl にオプションでヘッダーの設定が必要なので注意
$ curl -sSH "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" https://qiita.com/api/v2/authenticated_user
{"description":"","facebook_id":"","followees_count":44,"followers_count":2,"github_login_name":"itooww","id":"itooww","items_count":2,"linkedin_id":"","location":"","name":"","organization":"","permanent_id":79267,"profile_image_url":"https://qiita-image-store.s3.amazonaws.com/0/79267/profile-images/1473701386","twitter_screen_name":"itooww","website_url":"","image_monthly_upload_limit":104857600,"image_monthly_upload_remaining":104857600,"team_only":false}

レスポンスを見やすくする

$ curl -sSH "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" https://qiita.com/api/v2/authenticated_user | jq -C .
{
  "description": "",
  "facebook_id": "",
  "followees_count": 44,
  "followers_count": 2,
  "github_login_name": "itooww",
  "id": "itooww",
  "items_count": 2,
  "linkedin_id": "",
  "location": "",
  "name": "",
  "organization": "",
  "permanent_id": 79267,
  "profile_image_url": "https://qiita-image-store.s3.amazonaws.com/0/79267/profile-images/1473701386",
  "twitter_screen_name": "itooww",
  "website_url": "",
  "image_monthly_upload_limit": 104857600,
  "image_monthly_upload_remaining": 104857600,
  "team_only": false
}

長いレスポンスを less で見る

$ curl -sSH "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" https://qiita.com/api/v2/authenticated_user/items | jq -C . | less -R

検証環境


$ curl --version
curl 7.52.1 (i686-pc-cygwin) libcurl/7.52.1 OpenSSL/1.0.2j zlib/1.2.8 libidn2/0.11 libpsl/0.14.0 (+libidn2/0.11) libssh2/1.7.0 nghttp2/1.14.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: Debug IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy Metalink PSL

$ jq --version
jq-1.5

$ less --version
less 481 (POSIX regular expressions)
Copyright (C) 1984-2015  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less

Reference

所感

  • コマンドが長くなりすぎると入力とか面倒なので curl 以外で手軽な方法あれば知りたい・・・
    • API 試すアプリとかインストールするのは抵抗あるので cli で完結したいならスクリプト作れって話になりそう

EOF

6
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6