Courtney Harris
Courtney Harris

Reputation: 1

API Call returning Gibberish

I'm building a recipe app with Next.js and JS and using RapidAPI for the api. I used the JS axios snippet for the api but when it tries to fetch, it shows the data as gibberish.

{data: '\x03�\x04\x00�̦���r��/椥f�b���\nfY\v�ݜX(«ձoi�<\x16X�KX�\x1A~3�&Ԁ��\x7F�…�����\rg�Y\x19��[\x15{<;R\x7F�܄E�_r��M�i�\x05��M��\x11��{X\r�e�7\x00\x03', status: 200, statusText: 'OK', headers: AxiosHeaders, config: {…}, …}
config
: 
{transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}
data
: 
"\u0003�\u0004\u0000�̦���r��/椥f�b���\nfY\u000b�ݜX(«ձoi�<\u0016X�KX�\u001a~3�&Ԁ���D\u0019��/L���\n��_\u0018� :\rH҄:��\f\u0011�R�\t�0��A�\b�Z�%v:e�X�S�}��_ϟ̽�!��� �\u000e��\u0010�P{�̃���{�!�����\u0018�\u000e\u000b�\"�Ag�Y\u001bg�\u001c/�:����qF4¬f�\u001biҁư��lPZ�Ţ(-α�\u0016EI�{�f�pF�\u0011-�\u0015��I.\u0015Ɛ�f�@�B>oI��\u001c�x\u0014��\u0012�j+�I?��\u0014q�\u0005��[��u�^�i�1b~{q�xvx��CT�D�'�Q�k�z���\u0011p\u0003��e\u0005��N�\u0003�r̷.p��&�{���Q��;GF�s�-�?��\u001c���*\b�'\u0016������ꈽ��c������\rg�Y\u0019��[\u0015{<;R�܄E�_r��M�i�\u0005��M��\u0011��{X\r�e�7\u0000\u0003"
headers
: 
AxiosHeaders {content-length: '928', content-type: 'application/json; charset=utf-8', date: 'Tue, 10 Jan 2023 00:14:52 GMT', etag: '"6fu9sm4bm6fx"', vary: 'Accept-Encoding'}
request
: 
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
status
: 
200
statusText
: 
"OK"
[[Prototype]]
: 
Object

Below is the call for the api. I don't know if it has something to do with my key or what. Any help would be greatly appreciated.

export default async function handler(req, res) {
   const options = {
      url: 'https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/complexSearch',
      params: {
         query: req.query.keyword,
         diet: req.query.diet,
         intolerances: req.query.intolerances,
         excludeIngredients: req.query.exclude,
         number: '20',
         offset: '0',
      },
      headers: {
         'X-RapidAPI-Host':
            'spoonacular-recipe-food-nutrition-v1.p.rapidapi.com',
         'X-RapidAPI-Key': process.env.NEXT_PUBLIC_RAPIDAPI_KEY,
      },
   };

   try {
      let response = await axios(options);
      res.status(200).json(response.data);
   } catch (error) {
      console.error(error.response);
   }
}

Upvotes: 0

Views: 20

Answers (0)

Related Questions