# Darf man sich schon was wünschen?

**URL:** <https://forum.shopware.com/t/darf-man-sich-schon-was-wunschen/56477>\
**Category:** Shopware Playground - API first Sandbox\
**Created:** [15. November 2018 um 18:20 UTC](https://forum.shopware.com/t/darf-man-sich-schon-was-wunschen/56477 "2018-11-15T18:20:20Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![Shopwareianer](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Shopwareianer](https://forum.shopware.com/u/Shopwareianer)\
**Post date:** [4. Dezember 2018 um 14:41 UTC](https://forum.shopware.com/t/darf-man-sich-schon-was-wunschen/56477/21 "2018-12-04T14:41:36Z")

</div>

@brettvormkopp‍ Bzgl. deiner Abfrage auf Basis eines Objekts. Habe da meine Class noch etwas überarbeitet. Ist jetzt aber nur für Filter.

```
export default class Api {
  constructor() {
    this.host = process.env.REACT_APP_API_URL;
    this.apiKey = process.env.REACT_APP_API_KEY;
  }

  async handleRequest(selector) {
    return fetch(this.host + selector.url, {
      method: selector.method,
      headers: {
        "x-sw-access-key": this.apiKey,
        "Content-Type": "application/json"
      }
    })
      .then(response => response.json())
      .then(json => json)
      .catch(error => console.error(error));
  }

  handleFilters(entityName, params) {
    const entity = entityName.replace("/", "");
    const filter = [];

    for (const key in params) {
      if (params.hasOwnProperty(key)) {
        const url = `filter[${entity}.${key}]=${params[key]}`;
        filter.push(url);
      }
    }

    const result = "?" + filter.join("&");
    return result;
  }

  getResult(entityName, params) {
    let url = "";
    if (params !== undefined) {
      url = `${entityName}${this.handleFilters(entityName, params)}`;
    } else {
      url = `${entityName}`;
    }
    return this.handleRequest({
      url,
      method: "GET"
    });
  }
}

```

Den Request machste dann bspw. mit:

```
await this.shop.getResult("product/", {
    categoryTree: this.props.match.params.categoryId,
    weitererFilter: value,
});

```

&nbsp;

---

_[View the full topic](https://forum.shopware.com/t/darf-man-sich-schon-was-wunschen/56477)._
