0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【備忘録】業務で実際使用したcurlコマンドメモ③(JSON形式)

Posted at

1.curlコマンドとは

curlコマンドとは、様々な通信プロトコル(手段)でデータの送受信を行うことができるコマンドです。
curlコマンド・オプション表はこちら

2.JSONとは

JSONとはJavaScript Object Notationの略で、JavaScript オブジェクトの構文に従ったテキストベースのデータ形式です。
Python、PHP、JavaScript、C++、Javaなど様々な言語でサポートされており、JSONを間に挟むことで各プログラミング言語間のデータの受け渡しがとても簡単にできます。

JSONの例)

[
  {"name" : "tanaka" , "age" : 20},
  {name" : "yamada" , "age" : 35}
]

JSONは {} の中にキーと値(value)をコロンで区切って記述します。
キーは必ずダブルクォーテーションで囲む必要があり、シングルクォーテーションだとエラーになります。

3.JSON形式でデータをPOSTしたい場合

サーバーとクライアント間の通信や、サーバー間での連携を行う仕組みとして、「API」という概念が存在します。
その中でも、多くのサーバーが対応しているのが「REST API」です。
REST APIはJSON形式でデータを記載することで、データの受け渡しや転送を行います。

データをJSON形式でPOSTしたい場合は、-HオプションでContent-Type:application/jsonを指定する。
送信するデータは-dでJSON文字列を指定する。

$ curl -X POST -H "Content-Type: application/json" -d '{"name":"花子", "age":25}' https://xxxxx.net/xxxxxx
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?