Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Arsitektur API Gateway
API Gateway adalah sistem pengelolaan API yang menyediakan pengelolaan, pemantauan, dan autentikasi untuk API Anda. Komponen yang membentuk API Gateway meliputi:
API Gateway: untuk mengelola semua aspek API yang di-deploy
Service Control: untuk menerapkan aturan pengelolaan API
Service Management: untuk mengelola konfigurasi API
gcloud CLI: untuk men-deploy dan mengelola API Anda
Google Cloud console: untuk logging, pemantauan, dan berbagi
Arsitektur
Berikut adalah diagram tingkat tinggi dari komponen utama yang terlibat dalam API Gateway:
Dalam diagram ini:
Penyedia API bertanggung jawab untuk membuat dan men-deploy API di API Gateway. Setiap API ditentukan oleh file yang ditulis sebagai spesifikasi OpenAPI 2.0.
Spesifikasi OpenAPI menentukan URL endpoint REST yang menghadap publik untuk API, layanan backend yang diakses oleh API, dan karakteristik API lainnya seperti autentikasi, format data, dan opsi respons.
Klien API membuat permintaan REST ke API yang dihosting di API Gateway untuk mengakses layanan backend. Klien API dapat berupa aplikasi apa pun yang mampu melakukan panggilan REST, seperti browser, aplikasi seluler, atau aplikasi web.
Klien API hanya perlu mengetahui URL API, kata kerja permintaan (seperti GET, PUT, POST, DELETE),
persyaratan autentikasi, dan format data yang dikirim ke atau diterima dari API.
Klien API tidak perlu mengetahui apa pun tentang implementasi backend. Bahkan, satu API yang dihosting di API Gateway dapat dikonfigurasi untuk mengakses backend yang berbeda berdasarkan informasi yang diteruskan dalam permintaan.
Komponen API Gateway
Gateway API
API Gateway menyediakan solusi terkelola sepenuhnya dengan model bayar sesuai penggunaan untuk menghosting API Anda. API Gateway memberikan akses yang aman ke layanan backend Anda melalui REST API yang ditentukan dengan baik dan konsisten di seluruh layanan Anda, terlepas dari implementasi layanan.
API Gateway terintegrasi dengan Google Cloud sehingga Anda dapat menggunakan alat pengembangan, pemantauan, logging, dan pelacakan yang sama dengan yang Anda gunakan dengan produk Google Cloud lainnya.
Jika terhubung ke layanan backend yang dihosting di luar Google Cloud, Anda tetap dapat memanfaatkan semua layanan Google Cloud , termasuk layanan autentikasi dan otorisasi yang digunakan untuk mengontrol akses ke API Anda.
Service Control API
Service Control API menerapkan aturan pengelolaan API saat runtime, seperti autentikasi kunci API, pemantauan, dan logging. Service Control menyediakan metode berikut:
Check: memverifikasi autentikasi dan kunci API, serta menunjukkan apakah panggilan harus diizinkan
Report: memberi tahu sistem pencatatan untuk logging dan pemantauan
Service Management API
Anda menggunakan spesifikasi OpenAPI untuk menentukan API Anda. Kemudian, Anda menggunakan gcloud CLI untuk mengupload spesifikasi OpenAPI ke Service Management, yang akan membuat konfigurasi API. Tugas terkait konfigurasi lainnya juga dilakukan di sini, seperti membagikan API Anda kepada developer lain, mengaktifkan atau menonaktifkan API di berbagai project, dan membuat kunci API.
gcloud CLI
gcloud CLI menyediakan alat command line gcloud yang dapat Anda gunakan untuk melakukan panggilan ke berbagai layanan Google Cloud . Anda menggunakan Google Cloud CLI untuk mengupload spesifikasi OpenAPI, yang membuat konfigurasi API, lalu men-deploy konfigurasi API ke API Gateway.
Cloud Console
Google Cloud console adalah antarmuka pengguna grafis untuk Google Cloud console. Gunakan konsol Google Cloud untuk mengekspos data pemantauan dan logging yang dicatat oleh Service Control, untuk mengonfigurasi autentikasi dan otorisasi, serta bagi developer untuk membuat kunci API guna memanggil API.
Menangani permintaan API
Dalam konfigurasi API, ada dua jenis endpoint:
Endpoint API: menentukan endpoint yang tersedia secara publik yang digunakan klien untuk menggunakan API Anda.
Endpoint backend: menentukan endpoint yang digunakan API untuk terhubung ke layanan backend Anda. Setelan keamanan, seperti akses HTTP atau HTTPS, ditentukan oleh penerapan layanan backend.
Permintaan ke endpoint API Anda diteruskan ke endpoint backend, termasuk data apa pun yang diteruskan sebagai bagian dari permintaan. Respons dari layanan backend, termasuk data apa pun yang ditampilkan oleh layanan, diteruskan kembali ke klien.
Perutean permintaan
Saat permintaan diterima:
API Gateway membuat token rekaman aktivitas untuk Cloud Trace.
API Gateway mencocokkan jalur permintaan masuk dengan API target. Setelah menemukan rute yang cocok, API Gateway akan melakukan langkah-langkah autentikasi untuk API yang ditentukan.
Jika validasi JWT diperlukan, Gateway API akan memvalidasi autentikasi menggunakan kunci publik yang sesuai untuk penanda tangan, dan memvalidasi kolom audiens di JWT. Jika kunci API diperlukan, API Gateway akan memanggil Service Control API untuk memvalidasi kunci.
Service Control akan mencari kunci untuk memvalidasinya, dan memastikan bahwa project yang terkait dengan kunci tersebut telah mengaktifkan API. Jika kunci tidak valid atau project belum mengaktifkan API, panggilan akan ditolak dan dicatat melalui Service Control API.
Jika Service Control berhasil memvalidasi kunci, permintaan beserta semua header asli, ditambah header validasi JWT, jika sesuai, akan diteruskan ke backend.
Saat respons diterima dari backend, API Gateway akan menampilkan respons ke pemanggil dan mengirimkan informasi waktu akhir ke Trace. Titik panggilan dicatat oleh Service Control API, yang kemudian menulis metrik dan log ke tujuan yang sesuai.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-03 UTC."],[[["\u003cp\u003eAPI Gateway is a fully managed system for API management, providing a secure, consistent REST API for backend services and handling authentication, monitoring, and logging.\u003c/p\u003e\n"],["\u003cp\u003eThe API provider defines APIs using OpenAPI specs, and API clients access these APIs without needing to know the backend implementation, while the client is only required to know the URL and the format of the API.\u003c/p\u003e\n"],["\u003cp\u003eService Control API handles API management rules at runtime, including API key validation, logging, and monitoring through methods like Check and Report.\u003c/p\u003e\n"],["\u003cp\u003eService Management API manages API configurations, such as creating the API config, sharing the API, and enabling or disabling the API in projects.\u003c/p\u003e\n"],["\u003cp\u003eWhen an API request is received, API Gateway routes the request to the correct backend service after performing authentication and validation, then returns the backend's response to the client, while also logging the call and sending metrics.\u003c/p\u003e\n"]]],[],null,["# API Gateway Architecture\n========================\n\nAPI Gateway is an API management system that provides management, monitoring, and authentication for your APIs. The components that make up API Gateway include:\n\n- **API Gateway**: for managing all aspects of a deployed API\n- **Service Control**: for applying API management rules\n- **Service Management**: for managing API configurations\n- **gcloud CLI**: for deploying and managing your APIs\n- **Google Cloud console**: for logging, monitoring and sharing\n\nArchitecture\n------------\n\nThe following is a high level diagram of the major components involved in API Gateway:\n\nIn this diagram:\n\n- **The API provider** is responsible for creating and deploying an API on API Gateway. Each API is defined by a file written as an OpenAPI 2.0 spec.\n\n The OpenAPI spec defines the publicly facing URL of the REST endpoint for the API, the backend service accessed by the API, and any other characteristics of the API such as authentication, data format, and response options.\n- **The API client** makes a REST request to an API hosted on API Gateway to access backend services. An API client can be any app capable of making a REST call, such as a browser, mobile app, or web app.\n\n The API client only needs to know the URL of the API, the request verb (such as `GET`, `PUT`, `POST`, `DELETE`),\n any authentication requirements, and the format of any data sent to or received from the API.\n\n The API client does not need to know anything about the backend implementation. In fact, a single API hosted on API Gateway can be configured to access different backends based on information passed in the request.\n\nAPI Gateway components\n----------------------\n\n### API Gateway\n\nAPI Gateway provides a fully managed, pay-per-use solution for hosting your APIs. API Gateway provide secure access to your backend services through a well-defined REST API that is consistent across all of your services, regardless of the service implementation.\n\nAPI Gateway is integrated with Google Cloud so that you can use the same development, monitoring, logging, and trace tools that you use with any other Google Cloud product.\n\nIf you are connecting to a backend service hosted outside of Google Cloud, you can still take advantage of all Google Cloud services, including the authentication and authorization services used to control access to your APIs.\n\n### Service Control API\n\n[Service Control API](https://cloud.google.com/service-control/) applies API management rules at runtime, such as API key authentication, monitoring, and logging. Service Control provides the following methods:\n\n- **Check**: verifies authentication and API keys, and indicates whether a call should be permitted\n- **Report**: notifies the systems of record for logging and monitoring\n\n### Service Management API\n\nYou use the [OpenAPI specification](/endpoints/docs/openapi/openapi-overview) to define your API. You then use the gcloud CLI to upload the OpenAPI spec to Service Management, which creates the API config. Other configuration-related tasks also happen here, such as sharing your API with other developers, enabling or disabling the API in different projects, and generating API keys.\n\n### gcloud CLI\n\nThe [gcloud CLI](https://cloud.google.com/sdk/docs) provides the [gcloud](/sdk/gcloud/reference) command-line tool that you can use to make calls to various Google Cloud services. You use the Google Cloud CLI to upload your OpenAPI spec, which creates the API config, and then to deploy the API config to API Gateway.\n\n### Cloud console\n\n[Google Cloud console](https://console.cloud.google.com/) is the graphical user interface for Google Cloud console. Use the Google Cloud console to expose monitoring and logging data recorded by Service Control, to configure authentication and authorization, and for developers to generate API keys to call the API.\n\nHandling an API request\n-----------------------\n\nIn an API configuration, there are two types of endpoints:\n\n- **API endpoint**: defines the publicly available endpoint that clients use to consume your APIs.\n- **Backend endpoint**: defines the endpoint that the API uses to connect to your backend service. Security settings, such as HTTP or HTTPS access, are defined by the implementation of the backend service.\n\nRequests to your API endpoint are passed to the backend endpoint, including any data passed as part of the request. Responses from the backend service, including any data returned by the service, are passed back to the client.\n\n### Request routing\n\nWhen a request is received:\n\n1. API Gateway creates a trace token for Cloud Trace.\n\n2. API Gateway matches the path of the incoming requests with the target API. After finding a matching route, API Gateway performs any authentication steps for the specified API.\n\n3. If JWT validation is necessary, API Gateway validates the authentication using the appropriate public key for the signer, and validates the audience field in the JWT. If an API key is required, API Gateway calls the Service Control API to validate the key.\n\n4. Service Control looks up the key to validate it, and ensures that the project associated with the key has enabled the API. If the key isn't valid or the project hasn't enabled the API, the call is rejected and it is logged via the Service Control API.\n\n5. If Service Control successfully validates the key, the request along with all original headers, plus a JWT validation header, if appropriate, is forwarded to the backend.\n\n6. When a response is received from the backend, API Gateway returns the response to the caller and sends the final timing information to Trace. The call points are logged by the Service Control API, which then writes metrics and logs to their appropriate destinations.\n\nWhat's next\n-----------\n\n- [API Gateway Deployment Model](/api-gateway/docs/deployment-model)"]]