Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created June 12, 2022 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/a5a12d07d015c4039423b6cb909f1915 to your computer and use it in GitHub Desktop.
Save arun12209/a5a12d07d015c4039423b6cb909f1915 to your computer and use it in GitHub Desktop.
const recordMetadata = {
name: 'name',
email: 'email',
website: 'url',
amount: 'currency',
phone: 'phoneNumber',
closeAt: 'dateInFuture',
};
const ENDPOINT ='https://data-faker.herokuapp.com/collection'; //API endpoint
const POST_METHOD = 'POST'; //POST method
const CONTENT_TYPE = 'application/json; charset=utf-8';
export default function fetchDataHelper({ amountOfRecords }) {
/* The global fetch() method starts the process of fetching a resource from the network,
returning a promise which is fulfilled once the response is available.
*/
return fetch(ENDPOINT, {
method: POST_METHOD,
headers: {
'Content-Type': CONTENT_TYPE,
},
body: JSON.stringify({
amountOfRecords,
recordMetadata,
}),
}).then((response) => response.json());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment