Created
January 30, 2021 06:02
-
-
Save thawkin3/612304526e8776776b42db294335b909 to your computer and use it in GitHub Desktop.
Data source for jokes
This file contains 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
const { RESTDataSource } = require('apollo-datasource-rest') | |
class JokesAPI extends RESTDataSource { | |
constructor() { | |
super() | |
this.baseURL = 'https://dad-joke-dadabase-rest-api.herokuapp.com/' | |
} | |
async getJoke(id) { | |
return this.get(`jokes/${id}?_embed=ratings`) | |
} | |
async getJokes() { | |
return this.get('jokes?_embed=ratings') | |
} | |
async postJoke(jokeContent) { | |
return this.post('jokes', jokeContent) | |
} | |
async replaceJoke(joke) { | |
return this.put('jokes', joke) | |
} | |
async updateJoke(joke) { | |
return this.patch('jokes', { id: joke.id, joke }) | |
} | |
async deleteJoke(id) { | |
return this.delete(`jokes/${id}`) | |
} | |
} | |
module.exports = JokesAPI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment