How to use the got.defaults function in got

To help you get started, we’ve selected a few got examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / gh-got / index.js View on Github external
const create = () => got.create({
	options: got.mergeOptions(got.defaults.options, {
		json: true,
		token: process.env.GITHUB_TOKEN,
		baseUrl: process.env.GITHUB_ENDPOINT || 'https://api.github.com',
		headers: {
			accept: 'application/vnd.github.v3+json',
			'user-agent': 'https://github.com/sindresorhus/gh-got'
		}
	}),

	methods: got.defaults.methods,

	handler: (options, next) => {
		if (options.token) {
			options.headers.authorization = options.headers.authorization || `token ${options.token}`;
		}

		if (options.stream) {
			return next(options);
		}

		// TODO: Use async/await here when Got supports the `handler` being an async function
		return next(options)
			.then(response => { // eslint-disable-line promise/prefer-await-to-then
				response.rateLimit = getRateLimit(response);
				return response;
			})
github project-flogo / flogo-web / apps / server / src / api / v2 / runner / services / base-client.ts View on Github external
export function createBaseClient() {
  return got.create({
    options: got.mergeOptions(got.defaults.options, { json: true }),
    methods: got.defaults.methods,
    handler: requestLogger,
  });
}