REST APIは、システムが有用な機能やデータをインターネットを通じてアプリケーション開発者に公開する一般的な方法です。 RESTはRepresentational State Transferの略で、分散システムが一貫性のあるインタフェースをどのように公開できるかを記述するアーキテクチャーパターンと説明できます。 APIはApplication Programming Interfaceの略で、基本的には他のプログラムによって使用できる一連のソフトウェア機能群のことを指します(完全な定義を参照)。 たとえばTwilioは、メッセージの送信、電話の発信、電話番号の検索などに使用できるREST APIを提供しています。
Generally speaking, when people use the term REST API, they are referring to an API that is accessed via the HTTP protocol at a predefined set of URLs (uniform resource locators) representing the various resources with which interactions can occur.
A REST API will be made up of one or more resources. A resource is any information or content accessed at a given URL - resources could be JSON, images, HTML, or audio files. Resources can usually have one or more methods that can be performed on them over HTTP. Some of the most common are in the table below.
Method | 一般的な使用 |
---|---|
GET | Most often used to retrieve a resource at a given URL. Can be requested over and over without side effects. When your browser retrieves a web page, it is performing an HTTP GET request to retrieve that page and the assets on it. |
POST | サーバー上に新しいデータを作成するために多用されます。 POSTリクエストには通常、新規コメントの作成や銀行口座への課金のような処理が送信のたびに毎回実行されるという副作用があります。 |
PUT | データの更新に多く使用されます。 PUTリクエストは何度も送信でき、副作用がないことが期待されます(毎回同様の結果となるはずです)。 |
削除 | サーバーからリソースを削除するときに使用されます。 |
These HTTP verbs sometimes DO NOT map 1:1 to these tasks, but commonly REST APIs provide a "CRUD" interface to remote resources. "CRUD" stands for these four operations.
To send a text message with Twilio, for example, you Create a new Message resource. This creates an instance of the resource. You can then Read this instance later to review the message, Update the message body to redact the message, and even Delete the message.
RESTのアーキテクチャースタイルはさらに奥が深いものです。 RESTアーキテクチャーパターンとREST APIについては、下記の資料を参照してください。