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

Commit 7eb7de3

Browse files
committed
add lang switcher example to home page wip
1 parent e3f0701 commit 7eb7de3

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

docs/index.mdx

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,93 @@ It's what's missing between applications and infrastructure automation.
1616

1717
Oh, and it supports basically any language, like JavaScript, TypeScript, Python, Go, you name it.
1818

19-
<div className="">
20-
<Libraries minimal />
19+
<div className="flex items-center flex-col gap-4 mt-10">
20+
21+
<div className="not-prose">
22+
<LanguageSwitch />
23+
</div>
24+
25+
<div className="max-w-xl w-full">
26+
27+
<CodeSwitcher enableTransitions className="xl:max-h-[300px] w-full">
28+
29+
```javascript !! title:services/api.js
30+
import { api } from '@nitric/sdk'
31+
32+
const main = api('main')
33+
34+
main.get('/hello/:name', async ({ req, res }) => {
35+
const { name } = req.params
36+
ctx.res.body = `Hello ${name}`
37+
})
38+
```
39+
40+
```typescript !! title:services/api.ts
41+
import { api } from '@nitric/sdk'
42+
43+
const main = api('main')
44+
45+
main.get('/hello/:name', async ({ req, res }) => {
46+
const { name } = req.params
47+
ctx.res.body = `Hello ${name}`
48+
})
49+
```
50+
51+
```python !! title:services/example.py
52+
from nitric.application import Nitric
53+
from nitric.resources import api
54+
from nitric.context import HttpContext
55+
56+
main = api("main")
57+
58+
@main.get("/hello/:name")
59+
async def hello_world(ctx: HttpContext):
60+
name = ctx.req.params['name']
61+
ctx.res.body = f"Hello {name}"
62+
63+
Nitric.run()
64+
```
65+
66+
```go !! title:services/example/main.go
67+
// !collapse(1:5) collapsed
68+
import (
69+
"context"
70+
71+
"github.com/nitrictech/go-sdk/nitric"
72+
"github.com/nitrictech/go-sdk/nitric/apis"
73+
)
74+
75+
func main() {
76+
api := nitric.NewApi("main")
77+
78+
api.Get("/hello/:name", func(ctx *apis.Ctx) {
79+
name := ctx.Request.PathParams()["name"]
80+
ctx.Response.Body = []byte(fmt.Sprintf("Hello %s", name))
81+
})
82+
83+
nitric.Run()
84+
}
85+
```
86+
87+
```dart !! title:services/example.dart
88+
import 'package:nitric_sdk/nitric.dart';
89+
90+
void main() {
91+
final main = Nitric.api('main');
92+
93+
main.get('/hello/:name', (ctx) async {
94+
final name = ctx.req.pathParams["name"]!;
95+
ctx.res.body = "Hello $name";
96+
97+
return ctx;
98+
});
99+
}
100+
```
101+
102+
</CodeSwitcher>
103+
104+
</div>
105+
21106
</div>
22107

23108
If you're familiar Nitric already, you might want to jump to the [Installation](/getting-started/installation), [Guides](/guides) or [Resources](/apis) sections. Otherwise, keep reading to learn more about Nitric.

src/components/mdx.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export { HomeHeader } from '@/components/HomeHeader'
144144

145145
export { ShowIfLang } from '@/components/ShowIfLang'
146146

147-
export { Libraries } from '@/components/Libraries'
147+
export { LanguageSwitch } from '@/components/LanguageSwitch'
148148

149149
export { ImportCode } from '@/components/code/ImportCode'
150150

0 commit comments

Comments
 (0)