Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meteatamel/cloud-functions-api
A sample that shows how to use API Gateway with Cloud Functions
https://github.com/meteatamel/cloud-functions-api
Last synced: 2 days ago
JSON representation
A sample that shows how to use API Gateway with Cloud Functions
- Host: GitHub
- URL: https://github.com/meteatamel/cloud-functions-api
- Owner: meteatamel
- License: apache-2.0
- Created: 2022-02-03T14:37:25.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-23T12:55:16.000Z (almost 3 years ago)
- Last Synced: 2024-12-19T16:58:50.855Z (15 days ago)
- Language: Shell
- Homepage:
- Size: 42 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloud Functions API
In this sample, you will create an API with API Gateway where each path is
handled by a different Cloud Function.![API Gateway with Cloud Functions](image.png)
## Cloud Functions
We'll deploy two simple functions defined in [index.js](index.js):
```nodejs
exports.helloWorld = (req, res) => {
res.send('Hello, World');
};exports.byeWorld = (req, res) => {
res.send('Bye, World');
};
```Deploy both functions:
```sh
./1_deploy_functions.sh
```## API Gateway
### Create an API
Enable required services for API Gateway and create a `greeter-api` API:
```sh
./2_create_api.sh
```### Create an API config
Create an API config using the OpenAPI spec to define which path goes to which
function.We'll use [openapi2-functions.yaml](openapi2-functions.yaml) as a starter but replace `REGION` and
`PROJECT_ID` with real values. This definition routes `/hello` to the
hello function and `/bye` to the bye function.```sh
./3_create_api_config.sh
```### Create a gateway
The final step is to deploy the API config to a gateway:
```sh
./4_create_gateway.sh
```## Test
To test the API, first fetch the default host name of the gateway and then make
a call with `/hello` and `/bye` paths:```sh
./5_test_gateway.sh
```You should see something similar:
```sh
# Test hello
curl https://greeter-gateway-5dvbajef.ew.gateway.dev/hello
Hello, World
# Test bye
curl https://greeter-gateway-5dvbajef.ew.gateway.dev/bye
Bye, World%
```