question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to add params to fetch

See original GitHub issue

First of all, thank you for this wonderful plugin! It has helped me quite a lot. I did run into a snag that I hope you can help with.

I am stumped trying to add params to the fetch action.

When I try this:

myModel.$fetch({
        params: {
          $limit: 100,
          $skip: 100
        }
      })

It ignores all of my params. Is there a way to add params to the fetch? Thanks again!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
KaniRobinsoncommented, Nov 1, 2018

@bluetetra and @malinushj I do appologise for the lack of documentation, i’ve been super busy with life, work and baby lol.

Example 1: if you want your url to have params such as /api/v1/users/:id

User.$fetch({
   params: { id: 1 }
})

Example 2: If your url has query params such as /api/v1/users?active=true

User.$fetch({
   query: { active: true }
})

Example 3: if your url has both query params and a param such as /api/v1/users/:id?active=true

User.$fetch({
   params: { id: 1 },
   query: { active: true }
})
1reaction
KaniRobinsoncommented, Nov 1, 2018

if you have url prefixes, such as /api/v1/users/folders but also have api/v1/folder you can do this on your model

  static methodConf = {
    http: {
      url: '/:prefix/folders'
    },
  }

and do the following:

// api/v1/users/folders
Folder.$fetch({
    params: { prefix: 'users' } 
})

// api/v1/folders
Folder.$fetch()

If you do not set a prefix, it will remove it from the endpoint 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting query string using Fetch GET request - Stack Overflow
A concise, modern approach: fetch('https://example.com?' + new URLSearchParams({ foo: 'value', bar: 2, })). How it works: When a string (e.g. the URL) is ......
Read more >
How to pass url query params? · Issue #256 · github/fetch
The fetch() operation simply uses the exact URL string as it was given. To pass the URL query params, simply have them in...
Read more >
How to Use the Fetch API (Correctly) - CODE Magazine
The first thing you should do is to assign the data parameter into the response property of the lastStatus property. This preserves the...
Read more >
Fetch URL scenario block - Bright Pattern Documentation
The Fetch URL block may take one of two conditional exits: Failed or No Data ... Click add to define URL parameters, type...
Read more >
Using the Fetch API with URLSearchParams in JavaScript
Your browser can't play this video. Learn more. Switch camera ... The new URLSearchParams Object integrates really well with the Fetch API.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found