Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit dcaa118

Browse files
committed
fix build by adding missing code examples
1 parent f82fec4 commit dcaa118

File tree

9 files changed

+467
-10
lines changed

9 files changed

+467
-10
lines changed

docs/batch.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ Within a Batch we create Job Definitions, by creating a new Job with a unique na
7070

7171
<CodeSwitcher tabs>
7272

73+
```javascript !!
74+
import { job } from '@nitric/sdk'
75+
76+
const analyze = job('analyze')
77+
78+
// Use `handler` to register the callback function that will run when a job is submitted
79+
analyze.handler(
80+
async (ctx) => {
81+
// Do some work
82+
},
83+
{ cpus: 1, memory: 1024, gpus: 0 },
84+
)
85+
```
86+
7387
```typescript !!
7488
import { job, JobContext } from '@nitric/sdk'
7589

@@ -153,6 +167,19 @@ api.post('/submit-job', async (ctx) => {
153167
})
154168
```
155169

170+
```typescript !!
171+
import * as nitric from '@nitric/sdk'
172+
173+
const api = nitric.api('public')
174+
const analyze = nitric.job('analyze').allow('submit')
175+
176+
api.post('/submit-job', async (ctx) => {
177+
await analyze.submit({
178+
someKey: 'someValue',
179+
})
180+
})
181+
```
182+
156183
```python !!
157184
from nitric.resources import api, job
158185
from nitric.application import Nitric

docs/further-reading/how-devs-use-nitric.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ An API named 'milkyway' with:
4040
- A storage bucket named planets_images.
4141
- This service intends to read and write content to the bucket.
4242

43-
<CodeSwitcher tabs>
43+
<Tabs>
44+
45+
<TabItem label="JavaScript">
4446

4547
```javascript !!
4648
import { api, kv, bucket } from '@nitric/sdk'
@@ -56,6 +58,10 @@ milkyWayApi.get('/planets/:id', async (ctx) => {
5658
})
5759
```
5860

61+
</TabItem>
62+
63+
<TabItem label="Python">
64+
5965
```python !!
6066
from nitric.resources import api, kv, bucket
6167
from nitric.application import Nitric
@@ -74,7 +80,9 @@ async def get_planet(ctx: HttpContext) -> None:
7480
Nitric.run()
7581
```
7682

77-
</CodeSwitcher>
83+
</TabItem>
84+
85+
</Tabs>
7886

7987
The resource specification is used to generate real-time visualizations of the application and will also be used during the deployment phase to automatically communicate the application’s runtime requirements to the deployment engine that provisions the resources.
8088

docs/guides/nodejs/amazon-cognito.mdx

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ nitric new
3232

3333
In this new Nitric project there will be an example API with a single `GET: /hello/:name` route. We'll start by securing this route.
3434

35-
<CodeSwitcher tabs>
35+
<Tabs syncKey="lang-node">
36+
37+
<TabItem label="TypeScript">
3638

3739
```typescript !! title:services/hello.ts
3840
import { api } from '@nitric/sdk'
@@ -46,6 +48,10 @@ helloApi.get('/hello/:name', async (ctx) => {
4648
})
4749
```
4850

51+
</TabItem>
52+
53+
<TabItem label="JavaScript">
54+
4955
```javascript !! title:services/hello.js
5056
import { api } from '@nitric/sdk'
5157

@@ -58,15 +64,19 @@ helloApi.get('/hello/:name', async (ctx) => {
5864
})
5965
```
6066

61-
</CodeSwitcher>
67+
</TabItem>
68+
69+
</Tabs>
6270

6371
## Rejecting unauthenticated requests with API Gateways
6472

6573
[Nitric APIs](/apis#api-security) allow initial token authentication to be performed by the API Gateways of various cloud providers, such as AWS API Gateway. When configured correctly this will ensure unauthenticated requests are rejected before reaching your application code.
6674

6775
To add this API Gateway authentication we need to create a `security definition` and then apply that definition to specific routes or the entire API. Here we'll update the `main` API by adding a new security definition named `cognito`.
6876

69-
<CodeSwitcher tabs>
77+
<Tabs syncKey="lang-node">
78+
79+
<TabItem label="TypeScript">
7080

7181
```typescript !! title:services/hello.ts
7282
import { api } from '@nitric/sdk'
@@ -90,6 +100,10 @@ helloApi.get('/hello/:name', async (ctx) => {
90100
})
91101
```
92102

103+
</TabItem>
104+
105+
<TabItem label="JavaScript">
106+
93107
```javascript !! title:services/hello.js
94108
import { api } from '@nitric/sdk'
95109

@@ -112,7 +126,9 @@ helloApi.get('/hello/:name', async (ctx) => {
112126
})
113127
```
114128

115-
</CodeSwitcher>
129+
</TabItem>
130+
131+
</Tabs>
116132

117133
<Note>
118134
You will need to update the `region`, `user-pool-id` and `app-client-id`
@@ -123,7 +139,9 @@ Next, we need to ensure this security definition is applied, otherwise it won't
123139

124140
In this example we'll apply the security at the API level, ensuring all routes require authentication.
125141

126-
<CodeSwitcher tabs>
142+
<Tabs syncKey="lang-node">
143+
144+
<TabItem label="TypeScript">
127145

128146
```typescript !! title:services/hello.ts
129147
import { api } from '@nitric/sdk'
@@ -151,6 +169,10 @@ helloApi.get('/hello/:name', async (ctx) => {
151169
})
152170
```
153171

172+
</TabItem>
173+
174+
<TabItem label="JavaScript">
175+
154176
```javascript !! title:services/hello.js
155177
import { api } from '@nitric/sdk'
156178

@@ -177,7 +199,9 @@ helloApi.get('/hello/:name', async (ctx) => {
177199
})
178200
```
179201

180-
</CodeSwitcher>
202+
</TabItem>
203+
204+
</Tabs>
181205

182206
<Note>
183207
It's worth noting that these security definitions are *not* enforced when
@@ -197,7 +221,9 @@ In the example below we're simply checking whether the user is a member of a par
197221
handlers or middleware.
198222
</Note>
199223

200-
<CodeSwitcher tabs>
224+
<Tabs syncKey="lang-node">
225+
226+
<TabItem label="TypeScript">
201227

202228
```typescript !! title:services/hello.ts
203229
import { api, HttpContext, HttpMiddleware } from '@nitric/sdk'
@@ -268,6 +294,10 @@ helloApi.get('/hello/:name', async (ctx: AuthContext) => {
268294
})
269295
```
270296

297+
</TabItem>
298+
299+
<TabItem label="JavaScript">
300+
271301
```javascript !! title:services/hello.js
272302
import { api, HttpContext } from '@nitric/sdk'
273303
import * as jwt from 'jsonwebtoken'
@@ -329,7 +359,9 @@ helloApi.get('/hello/:name', async (ctx) => {
329359
})
330360
```
331361
332-
</CodeSwitcher>
362+
</TabItem>
363+
364+
</Tabs>
333365
334366
## Testing authentication and authorization
335367

docs/keyvalue.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ await countries.set('USA', {
100100
})
101101
```
102102

103+
```typescript !!
104+
import { kv } from '@nitric/sdk'
105+
106+
const countries = kv('Countries').allow('set')
107+
108+
await countries.set('USA', {
109+
name: 'United States of America',
110+
population: 329500000,
111+
})
112+
```
113+
103114
```python !!
104115
from nitric.resources import kv
105116
from nitric.application import Nitric
@@ -160,6 +171,13 @@ await countries.set('USA', {
160171
})
161172
```
162173

174+
```typescript !!
175+
await countries.set('USA', {
176+
name: 'United States of America',
177+
population: 330000000,
178+
})
179+
```
180+
163181
```python !!
164182
await countries.set('USA', {
165183
"name": "United States of America",
@@ -197,6 +215,14 @@ const countries = kv('Countries').allow('get')
197215
const country = await country.get('USA')
198216
```
199217

218+
```typescript !!
219+
import { kv } from '@nitric/sdk'
220+
221+
const countries = kv('Countries').allow('get')
222+
223+
const country = await country.get('USA')
224+
```
225+
200226
```python !!
201227
from nitric.resources import kv
202228
from nitric.application import Nitric
@@ -258,6 +284,19 @@ await countries.set('USA', {
258284
await countries.delete('USA')
259285
```
260286

287+
```typescript !!
288+
import { kv } from '@nitric/sdk'
289+
290+
const countries = kv('Countries').allow('delete', 'set')
291+
292+
await countries.set('USA', {
293+
name: 'United States of America',
294+
population: 329500000,
295+
})
296+
297+
await countries.delete('USA')
298+
```
299+
261300
```python !!
262301
from nitric.resources import kv
263302
from nitric.application import Nitric
@@ -332,6 +371,16 @@ for await (const key of countries.keys()) {
332371
}
333372
```
334373

374+
```typescript !!
375+
import { kv } from '@nitric/sdk'
376+
377+
const countries = kv('Countries').allow('get')
378+
379+
for await (const key of countries.keys()) {
380+
console.log(key)
381+
}
382+
```
383+
335384
```python !!
336385
from nitric.resources import kv
337386
from nitric.application import Nitric

0 commit comments

Comments
 (0)