Skip to main content

register_resource

Function register_resource 

Source
pub fn register_resource<S: Store + 'static>(
    app: &mut LinoApp,
    base_path: &str,
    store: Arc<S>,
    options: ResourceOptions,
)
Expand description

Register the routes of a CRUD resource on an application.

ยงExamples

use std::sync::Arc;

use lino_rest_api::app::{LinoApp, RawRequest};
use lino_rest_api::resource::ResourceOptions;
use lino_rest_api::store::MemoryStore;
use lino_rest_api::value::{object, string};

let store = Arc::new(MemoryStore::seeded([object([("title", string("Ship it"))])]));
let mut app = LinoApp::new();
app.resource("/tasks", store, ResourceOptions::new().with_name("task"));

let response = app.respond(RawRequest::new("GET", "/tasks/1")).await;
assert_eq!(response.status, 200);
assert!(response.body.contains("Ship it"));