Quick Start
This guide takes the shortest path to expose a cloud function as a directly callable HTTPS endpoint: create a function → configure a route → verify access. It takes about 5 minutes, and the commands and code can be copied as-is.
When you are done, you get an address like https://<domain>/hello that returns the function's response.
Before you start
- A CloudBase environment already exists. See Create an environment
- Every environment comes with a default domain, which is fine for testing. For production, bind a custom domain
Step 1: Create a cloud function
- Go to the CloudBase console and select the target environment
- In the left menu, choose "Cloud Functions", click "New cloud function", and name it
helloWorld - Replace the function code with the following:
exports.main = async function () {
return "Hello World!";
};
- Click "Save and install dependencies" and wait for the deployment to finish
For runtime and dependency options, see Cloud function quick start.
Step 2: Configure an HTTP route
The HTTP Gateway matches requests by domain and path, then forwards them to a backend resource. A route is one such matching rule.
- Go to CloudBase console / HTTP Gateway and click "New" under Route Management
- Fill in the configuration as follows:
| Item | Value |
|---|---|
| Associated resource | Cloud function → helloWorld |
| Domain | A default domain, or a connected custom domain |
| Trigger path | /hello |
- Click "OK". Creation takes about 3-5 minutes; the route takes effect when its status becomes "Normal"
Step 3: Verify access
Once the route is active, the address is the domain plus the trigger path:
curl https://<your-domain>/hello
# Response: Hello World!
Open the same URL in a browser and it also shows Hello World!.
For public-facing services, bind a custom domain with ICP filing and configure an HTTPS certificate. See Custom domain. For limits on default domains, see Default domain access limits and interstitial page.
Next steps
- Route matching and priority: Route matching rules
- Request and response handling: Access cloud functions over HTTP
- Cross-origin calls from browsers: CORS settings
- Rate limits and caching: Rate limiting, Caching
- Troubleshooting access failures: FAQ