Skip to content

Commit 7b709c5

Browse files
committed
docs: remove outdated WebSockets section and update file upload example
1 parent 9384a4f commit 7b709c5

File tree

1 file changed

+3
-54
lines changed

1 file changed

+3
-54
lines changed

sites/docs/versioned_docs/version-0.5.x/advanced-features.md

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -333,55 +333,6 @@ async fn main() {
333333
}
334334
```
335335

336-
## WebSockets
337-
338-
Ngyn supports WebSockets for real-time communication:
339-
340-
```rust
341-
use ngyn::prelude::*;
342-
use futures::{SinkExt, StreamExt};
343-
use tokio::sync::broadcast;
344-
345-
#[handler]
346-
async fn websocket_handler(ws: WebSocket) -> Result<(), String> {
347-
// Accept the WebSocket connection
348-
let (mut sender, mut receiver) = ws.accept().await.map_err(|e| e.to_string())?;
349-
350-
// Create a channel for broadcasting messages
351-
let (tx, _rx) = broadcast::channel::<String>(100);
352-
let tx2 = tx.clone();
353-
354-
// Spawn a task to handle incoming messages
355-
tokio::spawn(async move {
356-
while let Some(Ok(message)) = receiver.next().await {
357-
if let Ok(text) = message.to_text() {
358-
println!("Received message: {}", text);
359-
let _ = tx.send(text.to_string());
360-
}
361-
}
362-
});
363-
364-
// Spawn a task to send messages to this client
365-
tokio::spawn(async move {
366-
let mut rx = tx2.subscribe();
367-
while let Ok(message) = rx.recv().await {
368-
let _ = sender.send(ngyn::ws::Message::text(message)).await;
369-
}
370-
});
371-
372-
Ok(())
373-
}
374-
375-
#[tokio::main]
376-
async fn main() {
377-
let mut app = HyperApplication::default();
378-
379-
app.get("/ws", websocket_handler);
380-
381-
let _ = app.listen("127.0.0.1:3000").await;
382-
}
383-
```
384-
385336
## File Uploads
386337

387338
Ngyn supports file uploads using multipart form data:
@@ -392,8 +343,10 @@ use futures::TryStreamExt;
392343
use std::io::Write;
393344

394345
#[handler]
395-
async fn upload_handler(multipart: Multipart) -> Result<JsonResult, String> {
346+
async fn upload_handler(body: Body) -> Result<JsonResult, String> {
396347
let mut uploaded_files = Vec::new();
348+
let multipart = body.to_multipart()
349+
.map_err(|e| e.to_string())?;
397350

398351
let mut multipart = multipart.into_inner();
399352

@@ -429,8 +382,4 @@ async fn main() {
429382
}
430383
```
431384

432-
## Conclusion
433-
434-
These advanced features allow you to build complex, production-ready applications with Ngyn. By leveraging dependency injection, middleware, gates, and integrations with databases and other services, you can create robust and maintainable web applications.
435-
436385
For more examples and detailed documentation, check out the [Ngyn repository](https://github.com/ngyn-rs/ngyn).

0 commit comments

Comments
 (0)