Using axios to GET data from flask-restless API

1.2k views Asked by At

I'm trying to use axios to get data from an flask-restless API. The following Python request works no problem:

import requests
import json

url = 'http://127.0.0.1:5001/api/cds'
headers = {'Content-Type': 'application/json'}

filters = [dict(name='formal_name', op='like', val='my_val')]
params = dict(q=json.dumps(dict(filters=filters)))

response = requests.get(url, params=params, headers=headers)

and generates this URI

/api/cds?q=%7B%22filters%22%3A+%5B%7B%22name%22%3A+%22formal_name%22%2C+%22op%22%3A+%22like%22%2C+%22val%22%3A+%22my_val%22%7D%5D%7D

A similar request with axios:

axios.get('http://127.0.0.1:5001/api/cds', {
      params: {
        q:
            JSON.stringify({
              filters: [{
                name: "formal_name",
                op: "like",
                val: formalName
              }]
            })
      },
    }
)
    .then(res => {
      console.log(res)
    });

requests a different URI:

/api/cds?q=%7B%22filters%22:[%7B%22name%22:%22formal_name%22,%22op%22:%22like%22,%22val%22:%22my_val%22%7D]%7D 

Which ends up returning no results. I'm wondering if I'm missing something in regards to the syntax I'm using in axios, or if there is some fundamental reason why axios is generating a different URI (which then cannot be parsed correctly by flask-restless)

1

There are 1 answers

0
nven On

This code worked as described above, there was an unrelated bug.