Skip to content

Instantly share code, notes, and snippets.

@chinhnguyen
Created May 22, 2023 07:52
Show Gist options
  • Save chinhnguyen/2ff9ff80629adf65f0955db4455d6d52 to your computer and use it in GitHub Desktop.
Save chinhnguyen/2ff9ff80629adf65f0955db4455d6d52 to your computer and use it in GitHub Desktop.
Ample Restful API example
interface Academic {
firstName: string
lastName: string
avatar: string
university: string
}
interface Question {
content: string
createdAt: Date
}
interface Comment {
createdAt: Date
createBy: Academic
isMostUseful: boolean
content: string
}
interface Commentary {
id: string
question: Question
comments: Comment[]
}
interface GetCommentariesResult {
total: number
commentaries: Commentary[]
}
const mediaPartnerId = process.env.AMPLE_API_ID
const mediaPartnerKey = process.env.AMPLE_API_KEY
async function getCommentaries(
url: URL,
from: number,
to: number
): Promise<GetCommentariesResult> {
const response = await Axios.get<GetCommentariesResult>(
`https://api.ampleviews.com/partners/${mediaPartnerId}/commentaries?url=${url.toString()}&from=${from}&to=${to}`,
{
headers: {
'x-api-key': mediaPartnerKey,
},
}
)
return response.data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment