Skip to main content

ndjson_response

Function ndjson_response 

Source
pub fn ndjson_response<S, T>(stream: S) -> Response
where S: Stream<Item = T> + Send + Unpin + 'static, T: Serialize + Send + Unpin + 'static,
Expand description

Convenience function to create an NDJSON response from a stream.

§Example

use fastapi_core::ndjson::ndjson_response;
use serde::Serialize;

#[derive(Serialize)]
struct Item { id: i64 }

let items = asupersync::stream::iter(vec![Item { id: 1 }, Item { id: 2 }]);
let response = ndjson_response(items);