1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use Result;
use Stk;
use crateBodyStrategy;
use crateBodyParser;
use crateApiRequest;
use crateFrozenContext;
use crateOptions;
use crateCursorDoc;
use crate;
use crate;
/// Middleware function that parses the request body according to the specified strategy.
///
/// This middleware deserializes the request body based on the `Content-Type` header
/// or the explicitly provided strategy. The parsed body replaces the raw bytes in `$request.body`.
///
/// # Arguments
/// * `req` - The API request object (modified in place)
/// * `next` - The next middleware or handler in the chain
/// * `strategy` - Optional deserialization strategy. If not provided, defaults to `Auto`:
/// - `Auto`: Detects format from `Content-Type` header
/// - `Json`: Always parse as JSON
/// - `Cbor`: Always parse as CBOR
/// - `Flatbuffers`: Always parse as Flatbuffers
/// - `Plain`: Always parse as plain text (UTF-8 string)
/// - `Bytes`: Keep as raw bytes (no parsing)
/// - `Native`: Parse as native SurrealDB format
///
/// # Returns
/// * `Ok(response)` - The response from the next middleware/handler
/// * `Err(e)` - Error if body parsing fails or Content-Type is invalid/missing
///
/// # Example
/// ```surql
/// DEFINE API "/users"
/// FOR post
/// MIDDLEWARE
/// api::req::body("json")
/// THEN {
/// // $request.body is now a parsed object, not raw bytes
/// RETURN {
/// status: 201,
/// body: { created: $request.body.name }
/// };
/// };
/// ```
pub async : ,
)