import { Router , Request , Response } from 'express' ; import axios from 'axios' ; export default Router ( ) . get ( '/posts' , getPosts ) ; export function getPosts ( req , res ) { const API = 'https://jsonplaceholder.typicode.com' ; return axios . get ( `${ API }/posts` ) . then ( posts => { res . status ( 200 ) . json ( { data : posts . data } ) ; } ) . catch ( error => { res . status ( 500 ) . json ( { error : 'Error' } ) ; } ) ; } ;