Skip to content

Instantly share code, notes, and snippets.

@ximxim
Created October 24, 2021 01:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ximxim/1a7c69f9b6c8714f686aa5f6a6f08ca9 to your computer and use it in GitHub Desktop.
Save ximxim/1a7c69f9b6c8714f686aa5f6a6f08ca9 to your computer and use it in GitHub Desktop.
Nextjs handler api/tokens/[id] to send static NFT metadata
import type { NextApiRequest, NextApiResponse } from "next";
/**
*
* @param req
* @param res
*
* This endpoint will return success response with an object that complies
* with OpenSea NFT standard. The object contains an image link to a giphy
* and the name of the asset.
*
* This handler can be used by making a get request to this link
* http://localhost:3000/api/tokens/1
*
* Check: https://docs.opensea.io/docs/metadata-standards
*/
async function handler(req: NextApiRequest, res: NextApiResponse) {
const tokenId = req.query.id as string;
res.status(200).json({
image: `https://media.giphy.com/media/X7IoVUJXtO3wk/giphy.gif`,
name: `Giphy #${tokenId}`,
});
}
export default handler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment