# Add language locale to API endpoint instead of locale suffix

**URL:** https://discourse.getcockpit.com/t/add-language-locale-to-api-endpoint-instead-of-locale-suffix/806
**Category:** Support
**Created:** [May 3, 2019, 1:33pm UTC](https://discourse.getcockpit.com/t/add-language-locale-to-api-endpoint-instead-of-locale-suffix/806 "2019-05-03T13:33:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ekntrtmz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/ekntrtmz/32/264_2.png) [@ekntrtmz](https://discourse.getcockpit.com/u/ekntrtmz)
#### Post date: [May 3, 2019, 1:33pm UTC](https://discourse.getcockpit.com/t/add-language-locale-to-api-endpoint-instead-of-locale-suffix/806/1 "2019-05-03T13:33:58Z")

</div>

I am using Cockpit in combination with Nuxt pre-render to asynchronously fetch data and generate static html files. Now I am trying to find an elegant way to prerender multi-language content. Currently I am fetching my data with axios and render the relevant endpoint depending on locales managed by nuxt-i18n module:

Fetching data from Cockpit:

```
  asyncData ( { $axios } ) {
return $axios.get(`/api/singletons/get/myData?token=XXX`)
.then((res) => {
  return { data: res.data }
})}

```

And render the html depending on locale:

```
<div>{{ data['myEndpoint_'+this.$i18n.locale] }}</div>

```

The upper solution is working but way too inefficient. It would be nice to have something like this instead:

```
      asyncData ( { $axios } ) {
return $axios.get(`/api/singletons/get/myData/'+this.$i18n.locale+'/?token=XXX`)
.then((res) => {
  return { data: res.data }
})}

```

For that I need Cockpit to add localized fields at the end of particular colletions/singletons, e.g.:

`/myData/myEndpoint_en ==> /myData/en/myEndpoint`

Is this possible with a custom cockpit addon?

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [May 3, 2019, 3:54pm UTC](https://discourse.getcockpit.com/t/add-language-locale-to-api-endpoint-instead-of-locale-suffix/806/2 "2019-05-03T15:54:10Z")

</div>

I don’t know, how Nuxt or axios work, but what about simply adding `&lang=en` to the url?

`return $axios.get('/api/singletons/get/myData/?token=XXX&lang='+this.$i18n.locale)`

---

<div class="post-metadata">

### Author: ![ekntrtmz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/ekntrtmz/32/264_2.png) [@ekntrtmz](https://discourse.getcockpit.com/u/ekntrtmz)
#### Post date: [May 3, 2019, 6:25pm UTC](https://discourse.getcockpit.com/t/add-language-locale-to-api-endpoint-instead-of-locale-suffix/806/4 "2019-05-03T18:25:53Z")

</div>

Yep that worked. Thank you for the simple way 🙂
