# Mocking API using Aurelia-cli

**URL:** <https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917>\
**Category:** Help Requests\
**Created:** [March 17, 2018, 1:18pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917 "2018-03-17T13:18:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SNO](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sno/32/650_2.png) [@SNO](https://discourse.aurelia.io/u/SNO)\
**Post date:** [March 17, 2018, 1:18pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/1 "2018-03-17T13:18:25Z")

</div>

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(data);
      }).catch(err=>{
          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,

---

<div class="post-metadata">

**Author:** ![SNO](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sno/32/650_2.png) [@SNO](https://discourse.aurelia.io/u/SNO)\
**Post date:** [March 17, 2018, 2:04pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/2 "2018-03-17T14:04:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [March 17, 2018, 6:15pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/3 "2018-03-17T18:15:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SNO](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sno/32/650_2.png) [@SNO](https://discourse.aurelia.io/u/SNO)\
**Post date:** [March 18, 2018, 12:48pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/4 "2018-03-18T12:48:34Z")

</div>

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:

> **[Creating a simple api mock service in Aurelia-cli](https://sascha-franke.blogspot.com/2018/03/creating-simple-api-mock-service-in.html)**
>
> Introduction In the last weeks I faced the challenge, that our central development API had several bugs so that I was not able to request...

Best regards,  
Sascha

---

<div class="post-metadata">

**Author:** ![Alexander-Taran](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/alexander-taran/32/2308_2.png) [@Alexander-Taran](https://discourse.aurelia.io/u/Alexander-Taran)\
**Post date:** [March 18, 2018, 4:24pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/5 "2018-03-18T16:24:23Z")

</div>

> [@SNO](#):
>
> So I tried to write a rough blog post

@SNO  
Would love if you could add it to cookbook here [https://github.com/aurelia-contrib/aurelia-getting-started/tree/master/guides](https://github.com/aurelia-contrib/aurelia-getting-started/tree/master/guides)

---

<div class="post-metadata">

**Author:** ![SNO](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sno/32/650_2.png) [@SNO](https://discourse.aurelia.io/u/SNO)\
**Post date:** [March 19, 2018, 8:38pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/6 "2018-03-19T20:38:07Z")

</div>

Done. Hope it’s fine for you.  
Create how-to-create-a-simple-aurelia-api-mock-service.md #27

---

<div class="post-metadata">

**Author:** ![Alexander-Taran](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/alexander-taran/32/2308_2.png) [@Alexander-Taran](https://discourse.aurelia.io/u/Alexander-Taran)\
**Post date:** [March 19, 2018, 8:45pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/7 "2018-03-19T20:45:05Z")

</div>

Cheers.  
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 .

---

<div class="post-metadata">

**Author:** ![SNO](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sno/32/650_2.png) [@SNO](https://discourse.aurelia.io/u/SNO)\
**Post date:** [March 19, 2018, 8:56pm UTC](https://discourse.aurelia.io/t/mocking-api-using-aurelia-cli/917/8 "2018-03-19T20:56:49Z")

</div>

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 ☹  
Next time I’ll provide it more detailed 😉
