@@ -89,7 +89,7 @@ The `insight` feature provides powerful real-time traffic analysis and debugging
8989
9090``` toml
9191[dependencies ]
92- rustapi-extras = { version = " 0.1" , features = [" insight" ] }
92+ rustapi-extras = { version = " 0.1.275 " , features = [" insight" ] }
9393```
9494
9595### Setup
@@ -118,3 +118,116 @@ async fn get_insights(State(store): State<Arc<InMemoryInsightStore>>) -> Json<In
118118```
119119
120120The ` InsightStore ` trait allows you to implement custom backends (e.g., ClickHouse or Elasticsearch) if you need long-term retention.
121+
122+ ## Observability
123+
124+ The ` otel ` and ` structured-logging ` features bring enterprise-grade observability.
125+
126+ ### OpenTelemetry
127+
128+ ``` rust
129+ use rustapi_extras :: otel :: {OtelLayer , OtelConfig };
130+
131+ let config = OtelConfig :: default (). service_name (" my-service" );
132+ let app = RustApi :: new ()
133+ . layer (OtelLayer :: new (config ));
134+ ```
135+
136+ ### Structured Logging
137+
138+ Emit logs as JSON for aggregators like Datadog or Splunk.
139+
140+ ``` rust
141+ use rustapi_extras :: structured_logging :: {StructuredLoggingLayer , JsonFormatter };
142+
143+ let app = RustApi :: new ()
144+ . layer (StructuredLoggingLayer :: new (JsonFormatter :: default ()));
145+ ```
146+
147+ ## Advanced Security
148+
149+ ### OAuth2 Client
150+
151+ The ` oauth2-client ` feature provides a complete client implementation.
152+
153+ ``` rust
154+ use rustapi_extras :: oauth2 :: {OAuth2Client , OAuth2Config , Provider };
155+
156+ let config = OAuth2Config :: new (
157+ Provider :: Google ,
158+ " client_id" ,
159+ " client_secret" ,
160+ " http://localhost:8080/callback"
161+ );
162+ let client = OAuth2Client :: new (config );
163+ ```
164+
165+ ### Security Headers
166+
167+ Add standard security headers (HSTS, X-Frame-Options, etc.).
168+
169+ ``` rust
170+ use rustapi_extras :: security_headers :: SecurityHeadersLayer ;
171+
172+ let app = RustApi :: new ()
173+ . layer (SecurityHeadersLayer :: default ());
174+ ```
175+
176+ ### API Keys
177+
178+ Simple API Key authentication strategy.
179+
180+ ``` rust
181+ use rustapi_extras :: api_key :: ApiKeyLayer ;
182+
183+ let app = RustApi :: new ()
184+ . layer (ApiKeyLayer :: new (" my-secret-key" ));
185+ ```
186+
187+ ## Resilience
188+
189+ ### Circuit Breaker
190+
191+ Prevent cascading failures by stopping requests to failing upstreams.
192+
193+ ``` rust
194+ use rustapi_extras :: circuit_breaker :: CircuitBreakerLayer ;
195+
196+ let app = RustApi :: new ()
197+ . layer (CircuitBreakerLayer :: new ());
198+ ```
199+
200+ ### Retry
201+
202+ Automatically retry failed requests with backoff.
203+
204+ ``` rust
205+ use rustapi_extras :: retry :: RetryLayer ;
206+
207+ let app = RustApi :: new ()
208+ . layer (RetryLayer :: default ());
209+ ```
210+
211+ ## Optimization
212+
213+ ### Caching
214+
215+ Cache responses based on headers or path.
216+
217+ ``` rust
218+ use rustapi_extras :: cache :: CacheLayer ;
219+
220+ let app = RustApi :: new ()
221+ . layer (CacheLayer :: new ());
222+ ```
223+
224+ ### Request Deduplication
225+
226+ Prevent duplicate requests (e.g., from double clicks) from processing twice.
227+
228+ ``` rust
229+ use rustapi_extras :: dedup :: DedupLayer ;
230+
231+ let app = RustApi :: new ()
232+ . layer (DedupLayer :: new ());
233+ ```
0 commit comments