Duck by Example


Typesafe fetching from JSON APIs

fn main() {
const response_json = match std::web::fetch("https://dummyjson.com/test").send() {
String @str => str,
.http_error => return,
};

const parsed = match parse_json<{status: String, method: String,}>(response_json) {
{ status: String, method: String } @response => response,
else => return,
};

std::io::println(parsed.status);
}

$ dargo runok

Server Side Rendering

component Counter(props: { initial_value: Int }) jsx {
const [value, setValue] = useState(props.initial_value);

return (
<>
<div>
<div>Current value: {value}</div>
<button onClick={() => setValue((v) => v + 1)}>Increment</button>
</div>
</>
);
}

template Page(props: { param: String }) duckx {
<html lang="en">
<body>
<p>You sent: {props.param}</p>
<...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help