Skip to content

Latest commit

 

History

History
56 lines (35 loc) · 1.58 KB

File metadata and controls

56 lines (35 loc) · 1.58 KB

Advanced Route Matching


🖥️ Try it yourself

$ spoof scaffold -o example-route-matching

Fixed routes

Mock API URLs can be fixed, like this:

"request": {   
  "path": "/api/hello"
}

(other parts of the JSON body have been hidden for clarity. See the scaffolded example for a complete file)


Parameterised routes

You can also include parameters in routes, like this:

"request": {   
  "path": "/api/{category:int}/products/{productName}"
}

The parts of the route surrounded by { } will match any value, as long as the type is correct.

You can expicitly match int or uuid. If you do not specify a type, any value will be matched.


Here are some examples:

Route Will match Will not match
/api/{$\textsf{\color{#0550ae}{name}}$}/products /api/$\textsf{\color{#4ac260}{foo}}$/products
/api/$\textsf{\color{#4ac260}{12345}}$/products,
/api/{$\textsf{\color{#0550ae}{category:int}}$}/products /api/$\textsf{\color{#4ac260}{123}}$/products /api/$\textsf{\color{#d15a5a}{foo}}$/products
/api/{$\textsf{\color{#0550ae}{category:uuid}}$}/products /api/$\textsf{\color{#4ac260}{832015d8-faaf-4bdc-8e4c-f2a410ba0028}}$/products /api/$\textsf{\color{#d15a5a}{foo}}$/products
/api/$\textsf{\color{#d15a5a}{66}}$/products


➡️ Next: Request Header Matching