Created
May 22, 2023 07:52
-
-
Save chinhnguyen/2ff9ff80629adf65f0955db4455d6d52 to your computer and use it in GitHub Desktop.
Ample Restful API example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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