Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response body type conversion to interface #1890

Closed
1 task done
vickyRathee opened this issue Oct 13, 2021 · 0 comments
Closed
1 task done

Response body type conversion to interface #1890

vickyRathee opened this issue Oct 13, 2021 · 0 comments

Comments

@vickyRathee
Copy link

I don't see any example on documentation to convert the response body to type T. I just need the response body as Array<Jobs> instead string.

I tried this

const response: Array<Jobs>  = await this._agentyApi(url, { method: "GET" });

and this

const response:   = await this._agentyApi<Array<Jobs>>(url, { method: "GET" });

But none of these supported

Here is full code

import got, { GotOptions } from "got";
import { Jobs } from "../models/jobs";

export class ApiService {
  _agentyApi: got.GotInstance;

  constructor() {
    this._agentyApi = got.extend({
      baseUrl: process.env.API_URL,
      throwHttpErrors: false,
      json: true,
      headers: {
        "Content-Type": "application/json;charset=UTF-8",
      },
    });
  }

  async getJobsAsync(): Promise<Array<Jobs>> {
    const url = "/queue";
    const response = await this._agentyApi<Array<Jobs>>(url, { method: "GET" });
    
    return response 
  }
}

Checklist

  • I have read the documentation.
Repository owner locked and limited conversation to collaborators Oct 13, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants