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

Commit da39283

Browse files
committed
add multi lang examples to arch services page
1 parent d71b980 commit da39283

File tree

1 file changed

+216
-4
lines changed

1 file changed

+216
-4
lines changed

docs/architecture/services.mdx

Lines changed: 216 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,109 @@ classDef edgeLabel line-height:2;
147147

148148
### Nitric service configuration - nitric.yaml
149149

150+
<CodeTabs>
151+
152+
<TabItem label="JavaScript">
153+
154+
```yaml
155+
name: service-name
156+
services:
157+
- match: ./services/*.js
158+
start: npm run dev:services $SERVICE_PATH
159+
runtime: node
160+
runtimes:
161+
node:
162+
dockerfile: ./node.dockerfile
163+
args: {}
164+
```
165+
166+
</TabItem>
167+
168+
<TabItem label="TypeScript">
169+
150170
```yaml
151171
name: service-name
152172
services:
153173
- match: services/*.ts
154-
runtime: ''
155-
type: ''
156174
start: npm run dev:services $SERVICE_PATH
175+
runtime: node
176+
runtimes:
177+
node:
178+
dockerfile: ./node.dockerfile
179+
args: {}
180+
```
181+
182+
</TabItem>
183+
184+
<TabItem label="Python">
185+
186+
```yaml
187+
name: service-name
188+
services:
189+
- match: services/*.py
190+
start: uv run watchmedo auto-restart -p *.py --no-restart-on-command-exit -R uv run $SERVICE_PATH
191+
runtime: python
192+
batch-services: []
193+
runtimes:
194+
python:
195+
dockerfile: ./python.dockerfile
196+
context: ''
197+
args: {}
198+
```
199+
200+
</TabItem>
201+
202+
<TabItem label="Go">
203+
204+
```yaml
205+
name: service-name
206+
services:
207+
- match: services/*
208+
start: go run ./$SERVICE_PATH/...
209+
runtime: go
210+
runtimes:
211+
go:
212+
dockerfile: ./golang.dockerfile
213+
args: {}
157214
```
158215
216+
</TabItem>
217+
218+
<TabItem label="Dart">
219+
220+
```yaml
221+
name: service-name
222+
services:
223+
- match: services/*.dart
224+
start: dart run --observe $SERVICE_PATH
225+
runtime: dart
226+
runtimes:
227+
dart:
228+
dockerfile: ./dart.dockerfile
229+
args: {}
230+
```
231+
232+
</TabItem>
233+
234+
</CodeTabs>
235+
159236
### HTTP Route Handler
160237
161-
```typescript
238+
<CodeSwitcher tabs>
239+
240+
```javascript !!
241+
import { api } from '@nitric/sdk'
242+
243+
const customerRoute = api('public').route(`/customers`)
244+
245+
customerRoute.get((ctx) => {
246+
// construct response for the GET: /customers request...
247+
const responseBody = {}
248+
ctx.res.json(responseBody)
249+
})
250+
```
251+
252+
```typescript !!
162253
import { api } from '@nitric/sdk'
163254

164255
const customerRoute = api('public').route(`/customers`)
@@ -170,9 +261,63 @@ customerRoute.get((ctx) => {
170261
})
171262
```
172263

264+
```python !!
265+
from nitric.resources import api
266+
from nitric.application import Nitric
267+
268+
customer_route = api("public").route("/customers")
269+
270+
@customer_route.get()
271+
async def get_customers(ctx):
272+
# construct response for the GET: /customers request...
273+
response_body = {}
274+
return ctx.json(response_body)
275+
276+
Nitric.run()
277+
```
278+
279+
```go !!
280+
package main
281+
282+
import (
283+
"github.com/nitrictech/go-sdk/nitric"
284+
"github.com/nitrictech/go-sdk/nitric/apis"
285+
)
286+
287+
func main() {
288+
customersRoute := nitric.NewApi("public").NewRoute("/customers")
289+
290+
customersRoute.Get(func(ctx *apis.Ctx) {
291+
ctx.Response.Body = []byte("Hello World")
292+
})
293+
294+
nitric.Run()
295+
}
296+
```
297+
298+
```dart !!
299+
import 'package:nitric_sdk/nitric.dart';
300+
301+
void main() {
302+
final customersRoute = Nitric.api("public").route("/customers");
303+
304+
customersRoute.get((ctx) async {
305+
// construct response for the GET: /customers request...
306+
final Map<String, dynamic> responseBody = {};
307+
ctx.res.json(responseBody);
308+
309+
return ctx;
310+
});
311+
}
312+
```
313+
314+
</CodeSwitcher>
315+
173316
### Bucket On Read/Write/Delete Handler
174317

175-
```typescript
318+
<CodeSwitcher tabs>
319+
320+
```javascript !!
176321
import { bucket } from '@nitric/sdk'
177322

178323
const assets = bucket('assets')
@@ -185,6 +330,73 @@ assets.on('delete', '*', (ctx) => {
185330
})
186331
```
187332

333+
```typescript !!
334+
import { bucket } from '@nitric/sdk'
335+
336+
const assets = bucket('assets')
337+
338+
const accessibleAssets = bucket('assets').allow('delete')
339+
340+
// The request will contain the name of the file `key` and the type of event `type`
341+
assets.on('delete', '*', (ctx) => {
342+
console.log(`A file named ${ctx.req.key} was deleted`)
343+
})
344+
```
345+
346+
```python !!
347+
from nitric.resources import bucket
348+
from nitric.application import Nitric
349+
350+
assets = bucket("assets")
351+
352+
accessible_assets = bucket("assets").allow("delete")
353+
354+
@assets.on("delete", "*")
355+
async def delete_asset(ctx):
356+
print(f"A file named {ctx.req.key} was deleted")
357+
358+
Nitric.run()
359+
```
360+
361+
```go !!
362+
package main
363+
364+
import (
365+
"fmt"
366+
367+
"github.com/nitrictech/go-sdk/nitric"
368+
"github.com/nitrictech/go-sdk/nitric/storage"
369+
)
370+
371+
func main() {
372+
assets := nitric.NewBucket("assets")
373+
374+
accessibleAssets := assets.Allow(storage.BucketDelete)
375+
376+
assets.On(storage.DeleteNotification, "*", func(ctx *storage.Ctx) {
377+
fmt.Printf("A file named %s was deleted", ctx.Request.Key())
378+
})
379+
380+
nitric.Run()
381+
}
382+
```
383+
384+
```dart !!
385+
import 'package:nitric_sdk/nitric.dart';
386+
387+
void main() {
388+
final assets = Nitric.bucket("assets");
389+
390+
final accessibleAssets = assets.allow([BucketPermission.delete]);
391+
392+
assets.on(BlobEventType.delete, "*", (ctx) {
393+
print("A file named ${ctx.req.key} was deleted");
394+
});
395+
}
396+
```
397+
398+
</CodeSwitcher>
399+
188400
**Operations** will use or extend the Nitric Terraform reference modules:
189401

190402
- [AWS Services Terraform Module](https://github.com/nitrictech/nitric/blob/main/cloud/aws/deploytf/.nitric/modules/service/main.tf)

0 commit comments

Comments
 (0)