Mocking API using Aurelia-cli

Hello together,

currently I’m trying to mock the api in aurelia-cli. My structure currently looks as follows:
Calling localhost:9000/api/v1/users/ should response a user index json.

I added the following folder Structure to my project:

  • api
    • v1
      • users
        • users.json

My User Index Class:

 this.HttpClient.fetch("http://localhost:9000/api/v1/users/", { 
          headers: {"Content-Type": "application/json", 'Accept': 'application/json'}, 
          method: "GET"
      .then(response => { 
          return response.json()})
      .then(data => {
          console.log("Error on requesting User Index");
          throw "Something went wrong on requesting the API for getting users, " + err;

The problem now is, that calling the mentioned route, I get an error… only calling localhost:9000/api/v1/users /users.json works, but this is not what I need to have.

Does anyone has an idea how I can solve that?

Best regards,

I guess that I now have a solution.
Using aurelia-configuration component, I can define the routes for dev, stage and prod directly in the configuratin file.

Can you share an example how you’d do it for your above scenario?

1 Like

Of course. Due to the discourse restrictions here, I was not able to post my code directly (because of too many “links”). So I tried to write a rough blog post:

Best regards,


Would love if you could add it to cookbook here

Done. Hope it’s fine for you.
Create #27

1 Like

I’ll take a look a bit later.
Seems it’s 1:1 your blog post.
If you don’t mind, I’ll probably add some more text. About it being one of the options and probably some comments around the code.

Thanks for your contribution, @SNO .

1 Like

Feel free . I’m happy when I can help.
Sorry that I couldn’t provide a more detailed guide. Currently I’ve not that much time that I can spend on that :frowning:
Next time I’ll provide it more detailed :wink:

1 Like