Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
API-Gateway-Architektur
API Gateway ist ein API-Verwaltungssystem, das die Verwaltung, Überwachung und Authentifizierung Ihrer APIs ermöglicht. API Gateway besteht aus folgenden Komponenten:
API-Gateway: zur Verwaltung aller Aspekte einer bereitgestellten API
Service Control: zur Anwendung von API-Verwaltungsregeln
Service Management: zum Verwalten von API-Konfigurationen
gcloud CLI: zum Bereitstellen und Verwalten Ihrer APIs
Google Cloud console: zum Protokollieren, Überwachen und Freigeben
Architektur
Das folgende Diagramm zeigt die wichtigsten Komponenten von API Gateway:
In diesem Diagramm gilt:
Der API-Anbieter ist für das Erstellen und Bereitstellen einer API in API Gateway verantwortlich. Jede API wird durch eine Datei definiert, die als OpenAPI 2.0-Spezifikation geschrieben ist.
Die OpenAPI-Spezifikation definiert die öffentlich zugängliche URL des REST-Endpunkts für die API, den von der API aufgerufenen Back-End-Dienst und alle anderen Merkmale der API, z. B. Authentifizierung, Datenformat und Antwortoptionen.
Der API-Client sendet eine REST-Anfrage an eine in API Gateway gehostete API, um auf Backend-Dienste zuzugreifen. Ein API-Client kann jede App sein, die einen REST-Aufruf ausführen kann, z. B. ein Browser, eine mobile App oder eine Web-App.
Der API-Client benötigt nur die URL der API, das Anfrageverb (z. B. GET, PUT, POST, DELETE), Authentifizierungsanforderungen und das Format aller Daten, die an die API gesendet oder von dieser empfangen werden.
Der API-Client muss nichts über die Backend-Implementierung wissen. Tatsächlich kann eine einzelne API, die in API Gateway gehostet wird, so konfiguriert werden, dass basierend auf den in der Anfrage übergebenen Informationen auf verschiedene Backends zugegriffen wird.
API Gateway-Komponenten
API Gateway
API Gateway bietet eine vollständig verwaltete Pay-per-Use-Lösung für das Hosting Ihrer APIs. API Gateway bietet sicheren Zugriff auf Ihre Backend-Dienste über eine klar definierte REST API, die über alle Dienste hinweg unabhängig von der Dienstimplementierung konsistent ist.
API Gateway ist in Google Cloud integriert, sodass Sie dieselben Entwicklungs-, Monitoring-, Logging- und Tracetools verwenden können wie bei jedem anderen Google Cloud -Produkt.
Wenn Sie eine Verbindung zu einem Backend-Dienst herstellen, der außerhalb von Google Cloudgehostet wird, können Sie weiterhin alle Google Cloud -Dienste nutzen, einschließlich der Authentifizierungs- und Autorisierungsdienste, die zum Steuern des Zugriffs auf Ihre APIs verwendet werden.
Service Control API
Die Service Control API wendet API-Verwaltungsregeln wie API-Schlüsselauthentifizierung, Monitoring und Logging zur Laufzeit an. Service Control bietet die folgenden Methoden:
Überprüfung: verifiziert Authentifizierungs- und API-Schlüssel und gibt an, ob ein Aufruf zugelassen werden soll
Bericht: benachrichtigt die Systeme über die Aufzeichnungen für Logging und Monitoring
Service Management API
Sie verwenden die OpenAPI-Spezifikation, um Ihre API zu definieren. Anschließend laden Sie die OpenAPI-Spezifikation mit der gcloud CLI in Service Management hoch. Dadurch wird die API-Konfiguration erstellt. Hier werden auch andere Konfigurationsaufgaben durchgeführt, z. B. das Freigeben der API für andere Entwickler, das Aktivieren oder Deaktivieren der API in verschiedenen Projekten und das Generieren von API-Schlüsseln.
gcloud-CLI
Die gcloud CLI enthält das gcloud-Befehlszeilentool, mit dem Sie Aufrufe an verschiedene Google Cloud -Dienste senden können. Sie verwenden die Google Cloud CLI, um Ihre OpenAPI-Spezifikation hochzuladen, mit der die API-Konfiguration erstellt wird, und um dann die API-Konfiguration für das API-Gateway bereitzustellen.
Cloud Console
Die Google Cloud Console ist die grafische Benutzeroberfläche für die Google Cloud Console. Verwenden Sie die Google Cloud Console, um Monitoring- und Loggingdaten anzuzeigen, die von Service Control aufgezeichnet wurden, um die Authentifizierung und Autorisierung zu konfigurieren und damit Entwickler API-Schlüsseln zum Aufrufen der API generieren können.
API-Anfrage bearbeiten
In einer API-Konfiguration gibt es zwei Arten von Endpunkten:
API-Endpunkt: Definiert den öffentlich verfügbaren Endpunkt, den Clients zum Verwenden Ihrer APIs verwenden.
Backend-Endpunkt: Definiert den Endpunkt, über den die API eine Verbindung zu Ihrem Backend-Dienst herstellt. Sicherheitseinstellungen wie HTTP- oder HTTPS-Zugriff werden durch die Implementierung des Back-End-Dienstes definiert.
Anfragen an Ihren API-Endpunkt werden an den Backend-Endpunkt weitergeleitet, einschließlich aller Daten, die als Teil der Anfrage übergeben werden. Antworten vom Backend-Dienst, einschließlich aller vom Dienst zurückgegebenen Daten, werden an den Client zurückgegeben.
Routing anfordern
Wenn eine Anfrage eingeht:
API Gateway erstellt ein Trace-Token für Cloud Trace.
API Gateway gleicht den Pfad der eingehenden Anfragen mit der Ziel-API ab. Nachdem eine passende Route gefunden wurde, führt API Gateway alle Authentifizierungsschritte für die angegebene API aus.
Wenn eine JWT-Validierung notwendig ist, validiert API Gateway die Authentifizierung mithilfe des passenden öffentlichen Schlüssels für den Signer und validiert das Zielgruppenfeld in JWT. Falls ein API-Schlüssel benötigt wird, ruft API Gateway die Service Control API auf, um den Schlüssel zu validieren.
Service Control sucht den Schlüssel, um ihn zu validieren, und überprüft, ob in dem Projekt, zu dem der Schlüssel gehört, die API aktiviert ist. Falls der Schlüssel nicht gültig ist oder die API im Projekt nicht aktiviert ist, wird der Aufruf zurückgewiesen. Dies wird durch die Service Control API protokolliert.
Falls Service Control den Schlüssel erfolgreich validiert, wird die Anfrage, zusammen mit den ursprünglichen Headern sowie, falls geeignet, einem JWT-Validierungs-Header an das Backend weitergeleitet.
Geht vom Backend eine Antwort ein, gibt API Gateway die Antwort an den Aufrufer zurück und schickt die endgültigen Zeitinformationen an Trace. Die Aufrufpunkte werden über die Service Control API erfasst, die Messdaten und Logs dann an die entsprechenden Ziele schreibt.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)"]]