Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Architettura del gateway API
API Gateway è un sistema di gestione delle API che fornisce gestione, monitoraggio e autenticazione per le tue API. I componenti che costituiscono API Gateway includono:
API Gateway: per gestire tutti gli aspetti di un'API di cui è stato eseguito il deployment
Service Control: per l'applicazione delle regole di gestione delle API
Service Management: per la gestione delle configurazioni API
gcloud CLI: per il deployment e la gestione delle API
consoleGoogle Cloud : per logging, monitoraggio e condivisione
Architettura
Di seguito è riportato un diagramma generale dei principali componenti coinvolti in API Gateway:
In questo diagramma:
Il fornitore dell'API è responsabile della creazione e del deployment di un'API su API Gateway. Ogni API è definita da un file scritto come specifica OpenAPI 2.0.
La specifica OpenAPI definisce l'URL pubblico dell'endpoint REST per l'API, il servizio di backend a cui accede l'API e qualsiasi altra caratteristica dell'API, come autenticazione, formato dei dati e opzioni di risposta.
Il client API effettua una richiesta REST a un'API ospitata su API Gateway per accedere ai servizi di backend. Un client API può essere qualsiasi app in grado di effettuare una chiamata REST, ad esempio un browser, un'app mobile o un'app web.
Il client API deve conoscere solo l'URL dell'API, il verbo della richiesta (ad esempio GET, PUT, POST, DELETE),
eventuali requisiti di autenticazione e il formato di tutti i dati inviati all'API o ricevuti da quest'ultima.
Il client API non deve sapere nulla dell'implementazione del backend. Infatti, una singola API ospitata su API Gateway può essere configurata per accedere a backend diversi in base alle informazioni trasmesse nella richiesta.
Componenti di API Gateway
API Gateway
API Gateway fornisce una soluzione completamente gestita e con pagamento a consumo per l'hosting delle tue API. API Gateway fornisce un accesso sicuro ai tuoi servizi di backend tramite un'API REST ben definita e coerente in tutti i tuoi servizi, indipendentemente dall'implementazione del servizio.
API Gateway è integrato con Google Cloud in modo da poter utilizzare gli stessi strumenti di sviluppo, monitoraggio, logging e tracciamento che utilizzi con qualsiasi altro prodotto Google Cloud .
Se ti connetti a un servizio di backend ospitato al di fuori di Google Cloud, puoi comunque usufruire di tutti i servizi Google Cloud , inclusi i servizi di autenticazione e autorizzazione utilizzati per controllare l'accesso alle tue API.
API Service Control
L'API Service Control applica regole di gestione delle API in fase di runtime, come l'autenticazione con chiave API, il monitoraggio e la registrazione. Service Control fornisce i seguenti metodi:
Check: verifica l'autenticazione e le chiavi API e indica se una chiamata deve essere consentita
Report: invia una notifica ai sistemi di registrazione per il logging e il monitoraggio
API Service Management
Utilizzi la specifica OpenAPI per definire la tua API. Quindi, utilizzi gcloud CLI per caricare la specifica OpenAPI in Service Management, che crea la configurazione API. Qui vengono eseguite anche altre attività correlate alla configurazione, come la condivisione dell'API con altri sviluppatori, l'attivazione o la disattivazione dell'API in progetti diversi e la generazione di chiavi API.
Interfaccia a riga di comando gcloud
La CLI gcloud fornisce lo strumento a riga di comando gcloud che puoi utilizzare per effettuare chiamate a vari servizi. Google Cloud Utilizzi Google Cloud CLI per caricare la specifica OpenAPI, che crea la configurazione API, e poi per eseguire il deployment della configurazione API in API Gateway.
console Cloud
Google Cloud console è la Graphic User Interface per Google Cloud console. Utilizza la console Google Cloud per esporre i dati di monitoraggio e di logging registrati da Service Control, per configurare l'autenticazione e l'autorizzazione e per consentire agli sviluppatori di generare chiavi API per chiamare l'API.
Gestione di una richiesta API
In una configurazione API, esistono due tipi di endpoint:
Endpoint API: definisce l'endpoint disponibile pubblicamente che i client utilizzano per utilizzare le tue API.
Endpoint di backend: definisce l'endpoint utilizzato dall'API per connettersi al tuo servizio di backend. Le impostazioni di sicurezza, come l'accesso HTTP o HTTPS, sono definite dall'implementazione del servizio di backend.
Le richieste all'endpoint API vengono trasmesse all'endpoint di backend, inclusi i dati trasmessi come parte della richiesta. Le risposte del servizio di backend, inclusi i dati restituiti dal servizio, vengono restituite al client.
Routing delle richieste
Quando viene ricevuta una richiesta:
API Gateway crea un token di traccia per Cloud Trace.
API Gateway associa il percorso delle richieste in entrata all'API di destinazione. Dopo aver trovato una route corrispondente, API Gateway esegue i passaggi di autenticazione per l'API specificata.
Se è necessaria la convalida JWT, API Gateway convalida l'autenticazione utilizzando la chiave pubblica appropriata per il firmatario e convalida il campo pubblico nel JWT. Se è necessaria una chiave API, API Gateway chiama l'API Service Control per convalidarla.
Service Control cerca la chiave per convalidarla e verifica che il progetto associato alla chiave abbia abilitato l'API. Se la chiave non è valida o se il progetto non ha abilitato l'API, la chiamata viene rifiutata e registrata tramite l'API Service Control.
Se Service Control convalida correttamente la chiave, la richiesta, insieme a tutte le intestazioni originali e a un'intestazione di convalida JWT, se appropriato, viene inoltrata al backend.
Quando viene ricevuta una risposta dal backend, API Gateway la restituisce al chiamante e invia le informazioni di temporizzazione finali a Trace. I punti di chiamata vengono registrati dall'API Service Control, che scrive quindi le metriche e i log nelle destinazioni appropriate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)"]]