zuplo 6.70.57 → 6.70.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,6 @@ title: Step 3 - API Key Authentication
3
3
  sidebar_label: "3 - API Key Auth"
4
4
  ---
5
5
 
6
- <QuickstartPicker
7
- mode="local"
8
- alternateLink="/articles/step-3-add-api-key-auth"
9
- />
10
-
11
6
  In this guide we'll add API Key authentication to a route. You can do this for
12
7
  any Zuplo project but will need a route, consider completing
13
8
  [Step 1](./step-1-setup-basic-gateway-local.mdx) first.
@@ -30,171 +25,126 @@ Let's get started.
30
25
 
31
26
  <Stepper>
32
27
 
33
- 1. Link your Local Project
34
-
35
- When developing locally with Zuplo, you can "link" your local project to
36
- your Zuplo project using the `zuplo link` command. This allows you to test
37
- your changes in a real environment.
38
-
39
- When you run the command you will be prompted to select your Zuplo account,
40
- project, and environment. You can pick any environment.
41
-
42
- ```bash
43
- npx zuplo link
44
- ```
45
-
46
- After your project is linked, environment variables and other configuration
47
- from your Zuplo project will be available in your local development
48
- environment.
49
-
50
- 1. Start your Project
51
-
52
- You can start your project using the following command:
53
-
54
- ```bash
55
- npx zuplo dev
56
- ```
57
-
58
- After your project is started, you can open the local route designer at
59
- http://localhost:9100.
60
-
61
- 1. Add the API Key Authentication Policy
28
+ 1. Add the API Key Authentication Policy
62
29
 
63
- Open the local **Route Designer** by navigating to http://localhost:9100/.
64
- Select your route and click **Add Policy** on the incoming request policies
65
- section.
30
+ Open the local **Route Designer** at http://localhost:9100. If your gateway
31
+ isn't already running, start it from your project directory with
32
+ `npm run dev`.
66
33
 
67
- <BrowserScreenshot url="http://localhost:9100/?path=routes.oas.json">
34
+ Select your route and click **Add Policy** on the incoming request policies
35
+ section.
68
36
 
69
- ![Add Policy](../../public/media/step-3-add-api-key-auth-local/image.png)
37
+ <BrowserScreenshot url="http://localhost:9100/?path=routes.oas.json">
70
38
 
71
- </BrowserScreenshot>
39
+ ![Add Policy](../../public/media/step-3-add-api-key-auth-local/image.png)
72
40
 
73
- Search for the API key authentication policy, click on it, and then click
74
- **Create Policy** to accept the default policy JSON.
41
+ </BrowserScreenshot>
75
42
 
76
- <ModalScreenshot>
43
+ Search for the API key authentication policy, click on it, and then click
44
+ **Create Policy** to accept the default policy JSON.
77
45
 
78
- ![Add API Key Authentication](../../public/media/step-3-add-api-key-auth/choose-policy.png)
46
+ <ModalScreenshot>
79
47
 
80
- </ModalScreenshot>
48
+ ![Add API Key Authentication](../../public/media/step-3-add-api-key-auth/choose-policy.png)
81
49
 
82
- :::tip
50
+ </ModalScreenshot>
83
51
 
84
- The API key authentication policy should usually be one of the first
85
- policies executed. If you came here from
86
- [Step 2](./step-2-add-rate-limiting.mdx) then you will want to drag it above
87
- the rate limiting policy.
52
+ :::tip
88
53
 
89
- :::
54
+ The API key authentication policy should usually be one of the first policies
55
+ executed. If you came here from
56
+ [Step 2](./step-2-add-rate-limiting-local.mdx) then you will want to drag it
57
+ above the rate limiting policy.
90
58
 
91
- ![reorder policies](../../public/media/step-3-add-api-key-auth/image-1.gif)
59
+ :::
92
60
 
93
- If you test your route, you should get a 401 Unauthorized response
61
+ ![reorder policies](../../public/media/step-3-add-api-key-auth/image-1.gif)
94
62
 
95
- ```json
96
- {
97
- "status": 401,
98
- "title": "Unauthorized",
99
- "type": "https://httpproblems.com/http-status/401"
100
- }
101
- ```
63
+ If you test your route, you should get a 401 Unauthorized response
102
64
 
103
- 1. Set up an API Key
65
+ ```json
66
+ {
67
+ "status": 401,
68
+ "title": "Unauthorized",
69
+ "type": "https://httpproblems.com/http-status/401"
70
+ }
71
+ ```
104
72
 
105
- In order to call your API, you need to configure an API consumer. In the
106
- Zuplo Portal, open the
107
- [**Services**](https://portal.zuplo.com/+/account/project/services) tab for
108
- your project, then click **Configure** on the "API Key Service".
73
+ 1. Set up an API Key
109
74
 
110
- :::warning
75
+ In order to call your API, you need to configure an API consumer. In the
76
+ Zuplo Portal, open the
77
+ [**Services**](https://portal.zuplo.com/+/account/project/services) tab for
78
+ your project, then click **Configure** on the "API Key Service".
111
79
 
112
- Be sure to select the appropriate environment in the dropdown on the top
113
- right of the services page. You must select the environment type you linked
114
- your local project to. If you only have a single environment, you should
115
- select "Production". Later we will create new environments for preview.
80
+ :::warning
116
81
 
117
- :::
82
+ Be sure to select the appropriate environment in the dropdown on the top
83
+ right of the services page. You must select the environment type your local
84
+ project is linked to. If you only have a single environment, you should
85
+ select "Production". Later we will create new environments for preview.
118
86
 
119
- ![API Key Service](../../public/media/step-3-add-api-key-auth/image-2.png)
87
+ :::
120
88
 
121
- Then click **Create Consumer**.
89
+ ![API Key Service](../../public/media/step-3-add-api-key-auth/image-2.png)
122
90
 
123
- ![Create Consumer](../../public/media/step-2-add-api-key-auth/image-8.png)
91
+ Then click **Create Consumer**.
124
92
 
125
- Let's break down the configuration needed.
126
- - Subject: Also known as `sub`. This is a unique identifier of the API
127
- consumer. This is commonly the name of the user or organization consuming
128
- your API
129
- - Key managers: The email addresses of those who will be managing this API
130
- key.
131
- - Metadata: JSON metadata that will be made available to the runtime when a
132
- key is used to authenticate. Common properties include the consumer's
133
- subscription plan, organization, etc.
93
+ ![Create Consumer](../../public/media/step-2-add-api-key-auth/image-8.png)
134
94
 
135
- Go ahead and fill in `test-consumer` for the Subject. Add your own email as
136
- a Key manager, and leave the metadata empty for now. Click **Save consumer**
137
- once you're done.
95
+ Let's break down the configuration needed.
96
+ - Subject: Also known as `sub`. This is a unique identifier of the API
97
+ consumer. This is commonly the name of the user or organization consuming
98
+ your API
99
+ - Key managers: The email addresses of those who will be managing this API
100
+ key.
101
+ - Metadata: JSON metadata that will be made available to the runtime when a
102
+ key is used to authenticate. Common properties include the consumer's
103
+ subscription plan, organization, etc.
138
104
 
139
- <ModalScreenshot>
105
+ Go ahead and fill in `test-consumer` for the Subject. Add your own email as a
106
+ Key manager, and leave the metadata empty for now. Click **Save consumer**
107
+ once you're done.
140
108
 
141
- ![New Consumer](../../public/media/step-3-add-api-key-auth/image-3.png)
109
+ <ModalScreenshot>
142
110
 
143
- </ModalScreenshot>
111
+ ![New Consumer](../../public/media/step-3-add-api-key-auth/image-3.png)
144
112
 
145
- 1. Copy your API Key
113
+ </ModalScreenshot>
146
114
 
147
- After your API Key consumer is created, copy your new API Key by clicking
148
- the copy button (next to the eye icon).
115
+ 1. Copy your API Key
149
116
 
150
- ![Copy Key](../../public/media/step-3-add-api-key-auth/image-4.png)
117
+ After your API Key consumer is created, copy your new API Key by clicking the
118
+ copy button (next to the eye icon).
151
119
 
152
- 1. Test out your API Key
120
+ ![Copy Key](../../public/media/step-3-add-api-key-auth/image-4.png)
153
121
 
154
- Using any HTTP client (like Postman or curl), make a request to your API.
122
+ 1. Test out your API Key
155
123
 
156
- ```bash
157
- curl --request GET \
158
- --url http://localhost:9000/path-1 \
159
- --header 'Authorization: Bearer zpka_d67b7e241bb948758f415b79aa8exxxx_2efbxxxx'
160
- ```
124
+ Using any HTTP client (like Postman or curl), make a request to your API.
161
125
 
162
- You should get a 401 Unauthorized response - as we haven't supplied the API
163
- key yet. Add a new `authorization` header with the value
164
- `Bearer <YOUR_API_KEY>` and insert the API Key you got from the developer
165
- portal.
126
+ ```bash
127
+ curl --request GET \
128
+ --url http://localhost:9000/todos \
129
+ --header 'Authorization: Bearer <YOUR_API_KEY>'
130
+ ```
166
131
 
167
- You should now get a 200 OK.
132
+ First, try without an authorization header — you should get a 401
133
+ Unauthorized response since the API Key policy is rejecting the request.
168
134
 
169
- ```json
170
- {
171
- "url": "https://echo.zuplo.io/path-1",
172
- "method": "GET",
173
- "query": {},
174
- "headers": {
175
- "accept": "*/*",
176
- "accept-encoding": "gzip, br",
177
- "connection": "Keep-Alive",
178
- "host": "echo.zuplo.io",
179
- "true-client-ip": "12.63.237.42",
180
- "user-agent": "curl/8.7.1",
181
- "x-forwarded-proto": "https",
182
- "x-real-ip": "12.63.237.42",
183
- "zp-rid": "ecfac0de-f039-4ced-997c-b17c9babc944"
184
- }
185
- }
186
- ```
135
+ Now include `Authorization: Bearer <YOUR_API_KEY>` with the key you just
136
+ copied. You should get a `200 OK` with the JSON list of todos.
187
137
 
188
- :::note
138
+ :::note
189
139
 
190
- We also offer an API for our API key service that allows you to
191
- programmatically create consumers and even create your own developer portal
192
- or integrate key management into your existing dashboard. See
193
- [this document for details](./api-key-api.mdx).
140
+ We also offer an API for our API key service that allows you to
141
+ programmatically create consumers and even create your own developer portal
142
+ or integrate key management into your existing dashboard. See
143
+ [this document for details](./api-key-api.mdx).
194
144
 
195
- :::
145
+ :::
196
146
 
197
147
  </Stepper>
198
148
 
199
149
  **NEXT** Try
200
- [Step 4 - Connect Source Control and Deploy to the Edge](./step-4-deploying-to-the-edge.mdx).
150
+ [Step 4 - Deploy to the Edge](./step-4-deploying-to-the-edge-local.mdx).
@@ -3,11 +3,6 @@ title: Step 3 - API Key Authentication
3
3
  sidebar_label: "3 - API Key Auth"
4
4
  ---
5
5
 
6
- <QuickstartPicker
7
- mode="portal"
8
- alternateLink="/articles/step-3-add-api-key-auth-local"
9
- />
10
-
11
6
  In this guide we'll add API Key authentication to a route. You can do this for
12
7
  any Zuplo project but will need a route, consider completing
13
8
  [Step 1](./step-1-setup-basic-gateway.mdx) first.
@@ -0,0 +1,106 @@
1
+ ---
2
+ title: Step 4 - Deploy to the Edge
3
+ sidebar_label: "4 - Deploy"
4
+ ---
5
+
6
+ In this guide we'll deploy your locally-developed gateway to the edge, at over
7
+ 300 data-centers around the world. Zuplo deploys from Git source control — once
8
+ your project is connected to a GitHub repository, every push deploys
9
+ automatically, with no CI/CD configuration required.
10
+
11
+ The act of deployment creates new [environments](./environments.mdx), so it's
12
+ worth familiarizing yourself with [how environments work](./environments.mdx).
13
+
14
+ To follow this tutorial you'll need a GitHub account (it's free, sign up at
15
+ [github.com](https://github.com)).
16
+
17
+ <Stepper>
18
+
19
+ 1. **Check your project status**
20
+
21
+ From your project directory, run `zuplo info` to see how your local project
22
+ maps to Zuplo:
23
+
24
+ ```bash
25
+ npx zuplo info
26
+ ```
27
+
28
+ ```bash
29
+ Project: example-project
30
+ Account: your-account
31
+ Portal: https://portal.zuplo.com/your-account/example-project
32
+ Environment Type: working-copy
33
+ Source Control: none, connect at https://portal.zuplo.com/your-account/example-project/settings/source-control-settings
34
+ ```
35
+
36
+ Notice the **Source Control** line shows `none` — your project isn't
37
+ connected to a repository yet. The next steps walk through connecting one so
38
+ your changes deploy automatically.
39
+
40
+ 1. **Create a GitHub repository**
41
+
42
+ In GitHub, [create a new repository](https://github.com/new). Leave it
43
+ **empty** — don't add a README, `.gitignore`, or license — since your project
44
+ already contains those files.
45
+
46
+ 1. **Push your project to GitHub**
47
+
48
+ `create-zuplo-api` already initialized your project as a Git repository.
49
+ Stage and commit your work (if you haven't already), then point your local
50
+ repo at the new GitHub repository and push:
51
+
52
+ ```bash
53
+ git add .
54
+ git commit -m "Initial commit"
55
+ git remote add origin https://github.com/your-account/example-project.git
56
+ git branch -M main
57
+ git push -u origin main
58
+ ```
59
+
60
+ 1. **Connect the repository in Zuplo**
61
+
62
+ Open the source-control settings link from the `zuplo info` output, or in the
63
+ Zuplo Portal open **Settings → Source Control**.
64
+
65
+ If this is your first time, click **Connect to GitHub** and authorize the
66
+ Zuplo GitHub app — see [GitHub Setup](./source-control-setup-github.mdx) for
67
+ a detailed walkthrough of the authorization flow and permissions.
68
+
69
+ Once the app has access to your repositories, find the repository you just
70
+ pushed to in the list and click **Connect**.
71
+
72
+ :::note{title="Non-empty repository warning"}
73
+
74
+ Because you already pushed your project, the portal will show a dialog
75
+ warning that the repository isn't empty and that connecting will only create
76
+ an association — no changes will be pushed or pulled automatically. That's
77
+ exactly what we want here, so click **Connect** to proceed.
78
+
79
+ :::
80
+
81
+ 1. **Verify your deployment**
82
+
83
+ As soon as the repository is connected, Zuplo deploys your `main` branch. In
84
+ GitHub you'll see a status check next to your commit; when it succeeds, the
85
+ deployment links to your new environment.
86
+
87
+ Run `zuplo info` again to confirm your project is now connected to source
88
+ control:
89
+
90
+ ```bash
91
+ npx zuplo info
92
+ ```
93
+
94
+ :::tip{title="Branch environments"}
95
+
96
+ Every branch you push gets its own isolated environment. Create a
97
+ `development` branch, push it, and Zuplo deploys a matching environment
98
+ automatically. See [Branch-Based Deployments](./branch-based-deployments.mdx)
99
+ to learn how branches map to environments.
100
+
101
+ :::
102
+
103
+ </Stepper>
104
+
105
+ **NEXT** Try
106
+ [Step 5 - Add Dynamic Rate Limiting](./step-5-dynamic-rate-limiting-local.mdx).
@@ -0,0 +1,180 @@
1
+ ---
2
+ title: Step 5 - Dynamic Rate Limiting
3
+ sidebar_label: "5 - Dynamic Rate Limiting"
4
+ ---
5
+
6
+ Fortune favors the bold. In this bonus getting started guide we'll show you how
7
+ to add dynamic rate limiting to your API, all from your local project.
8
+
9
+ To follow this tutorial you'll need to have completed
10
+ [Step 1](./step-1-setup-basic-gateway-local.mdx) for a Zuplo project,
11
+ [Step 2](./step-2-add-rate-limiting-local.mdx) to add rate limiting to a route,
12
+ and [Step 3](./step-3-add-api-key-auth-local.mdx) to add API key authentication
13
+ to that same route.
14
+
15
+ :::info{title="What's Dynamic Rate Limiting?"}
16
+
17
+ Traditionally, rate limits are static and the same for everyone. This approach
18
+ doesn't let you tailor your rate limiting to your API user - you might want to
19
+ offer higher rate limits for customers that pay more. Dynamic rate limiting
20
+ allows you to determine an appropriate rate limit at request time.
21
+
22
+ :::
23
+
24
+ Let's get started.
25
+
26
+ <Stepper>
27
+
28
+ 1. Add Consumer Metadata
29
+
30
+ Let's make our rate-limiting policy more dynamic, based on properties of the
31
+ customer. In the Zuplo Portal,
32
+ [create a new consumer](./step-3-add-api-key-auth-local.mdx) (Services → API
33
+ Key Service → Configure → Create Consumer), and in the Metadata field set the
34
+ following:
35
+
36
+ ```json
37
+ {
38
+ "customerType": "free"
39
+ }
40
+ ```
41
+
42
+ Update the metadata of your other API Key consumer (3-dot menu → Edit) from
43
+ Step 3 to:
44
+
45
+ ```json
46
+ {
47
+ "customerType": "premium"
48
+ }
49
+ ```
50
+
51
+ Now that there are users with different `customerType`, this information can
52
+ be used to rate limit them differently.
53
+
54
+ 1. Add a Custom Code Module
55
+
56
+ In your editor, create a new file at `modules/rate-limit.ts` in your project.
57
+
58
+ :::info{title="What's a Module?"}
59
+
60
+ Modules are TypeScript functions that you can execute within Zuplo. They're
61
+ typically used to add custom code within the request/response pipeline (for
62
+ example custom policies or request handlers). You can even perform network
63
+ requests and use libraries within these modules.
64
+
65
+ :::
66
+
67
+ Add the following code to your module:
68
+
69
+ ```ts
70
+ import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
71
+
72
+ export function rateLimit(request: ZuploRequest, context: ZuploContext) {
73
+ const user = request.user;
74
+
75
+ // premium customers get 1000 requests per minute
76
+ if (user.data.customerType === "premium") {
77
+ return {
78
+ key: user.sub,
79
+ requestsAllowed: 1000,
80
+ timeWindowMinutes: 1,
81
+ };
82
+ }
83
+
84
+ // free customers get 5 requests per minute
85
+ if (user.data.customerType === "free") {
86
+ return {
87
+ key: user.sub,
88
+ requestsAllowed: 5,
89
+ timeWindowMinutes: 1,
90
+ };
91
+ }
92
+
93
+ // everybody else gets 30 requests per minute
94
+ return {
95
+ key: user.sub,
96
+ requestsAllowed: 30,
97
+ timeWindowMinutes: 1,
98
+ };
99
+ }
100
+ ```
101
+
102
+ 1. Update your Policy
103
+
104
+ Now we'll reconfigure the rate-limiting policy to wire up our custom
105
+ function. Open the local **Route Designer** at http://localhost:9100, find
106
+ the policy, and click **Edit** — or edit `config/policies.json` directly in
107
+ your editor.
108
+
109
+ Update the configuration to:
110
+
111
+ ```json
112
+ {
113
+ "export": "RateLimitInboundPolicy",
114
+ "module": "$import(@zuplo/runtime)",
115
+ "options": {
116
+ "rateLimitBy": "function",
117
+ "requestsAllowed": 2,
118
+ "timeWindowMinutes": 1,
119
+ "identifier": {
120
+ "export": "rateLimit",
121
+ "module": "$import(./modules/rate-limit)"
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ By changing the `rateLimitBy` to `function` you are indicating the rate limit
128
+ will be determined by a module at runtime. The `identifier` property
129
+ indicates the module and function to run. Make sure to save once you've made
130
+ your changes.
131
+
132
+ :::tip
133
+
134
+ Dynamic rate limiting reads from `request.user`, so the API key
135
+ authentication policy from [Step 3](./step-3-add-api-key-auth-local.mdx) must
136
+ run **before** the rate-limiting policy.
137
+
138
+ :::
139
+
140
+ 1. Test your Policy
141
+
142
+ With your gateway running (`npm run dev`), try your dynamic rate limiting.
143
+ Grab the key for each consumer back in the Services tab where you created
144
+ them, then make calls with each key until you hit its limit.
145
+
146
+ ```bash
147
+ # free consumer — limited to 5 requests per minute
148
+ curl http://localhost:9000/todos \
149
+ --header 'Authorization: Bearer <FREE_CONSUMER_KEY>'
150
+
151
+ # premium consumer — allowed 1000 requests per minute
152
+ curl http://localhost:9000/todos \
153
+ --header 'Authorization: Bearer <PREMIUM_CONSUMER_KEY>'
154
+ ```
155
+
156
+ Observe the difference in rate limits between the two consumers.
157
+
158
+ </Stepper>
159
+
160
+ ## Wrapping up
161
+
162
+ Congratulations - you've just successfully built an API that's:
163
+
164
+ - Protected by API key Authentication
165
+ - Dynamically Rate Limited
166
+ - Deployed to the Edge for superior performance
167
+ - and fully documented via your Developer Portal
168
+
169
+ This is an API experience most companies dream of, and you've just built it in
170
+ less than an hour.
171
+
172
+ ### Next Steps
173
+
174
+ - Continue exploring our docs to learn about customizing your
175
+ [Developer Portal](../dev-portal/introduction.mdx), or explore our various
176
+ [Integrations](https://zuplo.com/integrations)
177
+ - [Grab time](https://zuplo.com/meeting) with the Zuplo team to have your
178
+ questions answered
179
+ - Start generating revenue from your new API with our
180
+ [Monetization tutorial](./monetization/index.mdx)
@@ -26,21 +26,21 @@ are provided with every support plan:
26
26
 
27
27
  Zuplo offers the following support plans:
28
28
 
29
- | Support Offer | Available to |
30
- | ----------------- | ------------------------------------------------------------------------------ |
31
- | Community Support | All customers |
32
- | Standard Support | Customers with any paid subscription plan or those in the initial trial period |
33
- | Premium Support | Customers who have purchased support as part of an enterprise plan |
29
+ | Support Offer | Available to |
30
+ | ----------------- | ------------------------------------------------------------------ |
31
+ | Community Support | All customers |
32
+ | Standard Support | Included for customers on an enterprise plan |
33
+ | Premium Support | Customers who have purchased support as part of an enterprise plan |
34
34
 
35
35
  ### Community support
36
36
 
37
- Customers with Zuplo's free subscription plan can seek support through the Zuplo
37
+ Customers on Zuplo's Free and Builder plans receive support through the Zuplo
38
38
  Community. Response times may vary and aren't guaranteed.
39
39
 
40
40
  ### Standard support
41
41
 
42
- Customers with a paid Zuplo subscription plan receive standard support which
43
- offers access to the following channels:
42
+ Customers on a Zuplo enterprise plan receive standard support which offers
43
+ access to the following channels:
44
44
 
45
45
  - Zuplo Community
46
46
  - Zuplo Email Support (best effort response times)