Background
We are using miragejs to mock server apis. Our server / backend, follows microservice architecture, and each microservice is versioned separately, and as a result and our api paths have
{base_version}
- server / release version, changes as per environment (dev / qa / uat / prod){microservice_version}
- different for each microservice on each environment
A typical api url looks like
example.com/
{base_version}
/microservice/{microservice_version}
/api_endpoint?parameter=value
Problem
While setting up routes for miragejs mocks,
- using wildcard (*) for both
{microservice_version}
, and{base_version}
fails, and results in a passthrough:
example.com/*/microservice/*/api_endpoint?parameter=value
but, all of the following work correctly:
- wildcard for
{base_version}
, and actual value for{microservice_version}
example.com/*/microservice/v2/api_endpoint?parameter=value
- wildcard for
{microservice_version}
, and actual value for{base_version}
example.com/v3/microservice/*/api_endpoint?parameter=value
- double wildcard (to escape
{microservice_version}
,{base_version}
, and anything in between)
example.com/**/api_endpoint?parameter=value
Either of the 3 working solutions above require us to hardcode one version, or ignore micro service name / path, which is not ideal, as we have multiple environments / releases, multiple micro service versions, and same api endpoints in different microservices (e.g. filters / attributes).
Is there a clean way to get miragejs to work with multiple wildcards in api url?
from mirage.js multiple wildcard passthrough
No comments:
Post a Comment