Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate axios in favor of native http? #47

Open
4lessandrodev opened this issue Feb 13, 2023 · 0 comments
Open

Deprecate axios in favor of native http? #47

4lessandrodev opened this issue Feb 13, 2023 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@4lessandrodev
Copy link
Owner

Deprecate "axios" in favor of native http?

Does it make sense to use the http provider's native implementation instead of using "axios"?

import https, { RequestOptions } from 'node:https';
import http from 'node:http';
import { Log, Step } from 'ts-logs';

const log = Log.init({ name: 'Test' });
log.addStep(Step.create({}));

const data = JSON.stringify(log);

const url = new URL('http://localhost:3001/test-002');

const options: RequestOptions = {
    hostname: url.hostname,
    port: url.port,
    path: url.pathname,
    method: 'POST',
    protocol: url.protocol,
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(data),
    },
}

const isHttps = url.protocol === 'https:' || url.port === '443' || url.href.includes('https://');

const request = isHttps ? https.request(options) : http.request(options);

request.write(data);
request.end();
@4lessandrodev 4lessandrodev self-assigned this Feb 13, 2023
@4lessandrodev 4lessandrodev added the question Further information is requested label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant