I want to achieve the same done here but in next.js.
            Asked
            
        
        
            Active
            
        
            Viewed 1,072 times
        
    1 Answers
0
            Next.js provides methods to fetch data from a server and using them as props. I don't know whether you want to use it before rendering a page (like getServerSideProps) or when, for example, you click a button, but I suppose its the first case.
My personal preference when doing requests, is axios, so I will use it in this example:
export async function getServerSideProps({ req, res }) {
    // Here is where we make the request
    const result = await axios({
        method: 'HEAD', // here is where we declare that we want to use the HEAD method
        url: "your server url", // this is the url where we want to send the request
        headers: {} // if you want to add custom headers, you can do it here
    })
    // Here we are logging the result of the request
    console.log(result)
}
You can refer to the next.js documentation on data fetching and the axios documentation
Have a great day and I hope you succeed on your projects
 
     
    