MCPcopy Create free account
hub / github.com/hashintel/hash / rest_api_router

Function rest_api_router

libs/@local/graph/api/src/rest/mod.rs:432–467  ·  view source on GitHub ↗

A [`Router`] that serves all of the REST API routes, and the `OpenAPI` specification.

(dependencies: RestRouterDependencies<S>)

Source from the content-addressed store, hash-verified

430
431/// A [`Router`] that serves all of the REST API routes, and the `OpenAPI` specification.
432pub fn rest_api_router<S>(dependencies: RestRouterDependencies<S>) -> Router
433where
434 S: StorePool + Send + Sync + 'static,
435 for<'p> S::Store<'p>: RestApiStore + PrincipalStore + PolicyStore,
436{
437 // All api resources are merged together into a super-router.
438 let merged_routes = api_resources::<S>()
439 .into_iter()
440 .fold(Router::new(), Router::merge)
441 .fallback(|| {
442 tracing::error!("404: Not found");
443 async { StatusCode::NOT_FOUND }
444 });
445
446 // super-router can then be used as any other router.
447 // Make sure extensions are added at the end so they are made available to merged routers.
448 // The `/api-doc` endpoints are nested as we don't want any layers or handlers for the api-doc.
449 // We use a `ServiceBuilder` to add the layers in the correct order.
450 let mut router = merged_routes
451 .layer(
452 ServiceBuilder::new()
453 .layer(NewSentryLayer::new_from_top())
454 .layer(SentryHttpLayer::default().enable_transaction()),
455 )
456 .layer(http_tracing_layer::HttpTracingLayer)
457 .layer(Extension(dependencies.store))
458 .layer(Extension(dependencies.temporal_client))
459 .layer(Extension(dependencies.domain_regex))
460 .layer(Extension(dependencies.api_config));
461
462 if let Some(query_logger) = dependencies.query_logger {
463 router = router.layer(Extension(query_logger));
464 }
465
466 router.merge(openapi_only_router())
467}
468
469async fn serve_static_schema(Path(path): Path<String>) -> Result<Response, StatusCode> {
470 let path = path.trim_start_matches('/');

Callers 1

start_serverFunction · 0.85

Calls 6

openapi_only_routerFunction · 0.85
defaultFunction · 0.50
fallbackMethod · 0.45
into_iterMethod · 0.45
layerMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected