mercredi 15 janvier 2020

Regular expression for matching dynamic part in url while mocking API is not working

I want to mock an API which has some dynamic part, so I tried to use a regular expression but it is not working.

URL is: https://example.com/programs/2fcce6e3-07ec-49a9-9146-fb84fb0105cf/subprogram/0f8ddca8-cf5a-4174-bc75-0928f71a0e87/metrics?activeOnly=false

The Id's after programs and subprograms are dynamic.

I tried to mock API by using a regular expression as below but it did not work.

const mock = RequestMock()
    .onRequestTo('https://example.com/programs/.*/subprogram/.*/metrics?activeOnly=false', { method: 'GET' })
    .respond(mockObject, 200, {
      'access-control-allow-origin': '*'
    });

Can someone please help me with this ?

Aucun commentaire:

Enregistrer un commentaire