Skip to content

Instantly share code, notes, and snippets.

@dhmlau
Last active June 12, 2021 01:27
Show Gist options
  • Save dhmlau/438f91f7578424d57f2fc972ebee1987 to your computer and use it in GitHub Desktop.
Save dhmlau/438f91f7578424d57f2fc972ebee1987 to your computer and use it in GitHub Desktop.
DataSource with REST Connector - GitHub API
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';
const config = {
name: 'githubds',
connector: 'rest',
baseURL: 'https://api.github.ibm.com',
crud: false,
options: {
headers: {
accept: 'application/json',
Authorization: process.env.TOKEN,
'User-Agent': 'loopback4-example-github',
'X-RateLimit-Limit': 5000,
'content-type': 'application/json'
}
},
operations: [
{
template: {
method: 'GET',
fullResponse: true,
url: 'https://api.github.com/search/issues?q=repo:{repo}+label:"{label}"'
},
functions: {
getIssuesByLabel: ['repo','label']
}
}, {
template: {
method: 'GET',
fullResponse: true,
url: '{url}'
},
functions: {
getIssuesByURL: ['url']
}
}, {
template: {
method: 'GET',
fullResponse: true,
url: 'https://api.github.com/search/issues?q=repo:{repo}+{querystring}'
},
functions: {
getIssuesWithQueryString: ['repo','querystring']
}
}
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment