├── .benchmarks └── output.txt ├── .eslintrc.json ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ └── feature-request.md ├── PULL_REQUEST_TEMPLATE │ └── template.md └── workflows │ ├── cd-document.yml │ ├── cd-release.yml │ ├── ci-benchmark.yml │ ├── ci-build.yml │ ├── ci-codeql.yml │ └── ci-lint-test.yml ├── .gitignore ├── .husky └── pre-commit ├── .lintstagedrc.json ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── PERFORMANCE.md ├── README.md ├── benchmarks ├── client.mjs ├── index.mjs ├── large.txt └── server.mjs ├── docs ├── .eslintrc.json ├── .gitignore ├── babel.config.js ├── blog │ └── 2021-04-06-welcome.md ├── docs │ ├── assets │ │ ├── axios.svg │ │ ├── got.svg │ │ ├── isomorphic-fetch.svg │ │ ├── node-fetch.svg │ │ ├── petitio.svg │ │ ├── phin.svg │ │ ├── r2.svg │ │ ├── request.svg │ │ └── superagent.svg │ ├── guides │ │ ├── basic-examples.md │ │ └── getting-started.md │ ├── index.md │ ├── metrics │ │ └── performance.md │ └── pkg │ │ ├── classes │ │ ├── petitiorequest.petitiorequest-1.md │ │ └── petitioresponse.petitioresponse-1.md │ │ ├── index.md │ │ ├── interfaces │ │ └── petitiorequest.timeoutoptions.md │ │ ├── modules.md │ │ └── modules │ │ ├── petitio.md │ │ ├── petitiorequest.md │ │ └── petitioresponse.md ├── docusaurus.config.js ├── i18n │ └── en-gb │ │ ├── code.json │ │ ├── docusaurus-plugin-content-docs │ │ ├── current.json │ │ ├── current │ │ │ ├── assets │ │ │ │ ├── axios.svg │ │ │ │ ├── got.svg │ │ │ │ ├── isomorphic-fetch.svg │ │ │ │ ├── node-fetch.svg │ │ │ │ ├── petitio.svg │ │ │ │ ├── phin.svg │ │ │ │ ├── r2.svg │ │ │ │ ├── request.svg │ │ │ │ └── superagent.svg │ │ │ ├── guides │ │ │ │ └── getting-started.md │ │ │ ├── index.md │ │ │ ├── metrics │ │ │ │ └── performance.md │ │ │ └── pkg │ │ │ │ ├── classes │ │ │ │ ├── petitiorequest.petitiorequest-1.md │ │ │ │ └── petitioresponse.petitioresponse-1.md │ │ │ │ ├── index.md │ │ │ │ ├── interfaces │ │ │ │ └── petitiorequest.timeoutoptions.md │ │ │ │ ├── modules.md │ │ │ │ └── modules │ │ │ │ ├── petitio.md │ │ │ │ ├── petitiorequest.md │ │ │ │ └── petitioresponse.md │ │ ├── version-1.2.0.json │ │ └── version-1.2.0 │ │ │ ├── assets │ │ │ ├── axios.svg │ │ │ ├── got.svg │ │ │ ├── isomorphic-fetch.svg │ │ │ ├── node-fetch.svg │ │ │ ├── petitio.svg │ │ │ ├── phin.svg │ │ │ ├── r2.svg │ │ │ ├── request.svg │ │ │ └── superagent.svg │ │ │ ├── guides │ │ │ └── getting-started.md │ │ │ ├── index.md │ │ │ ├── metrics │ │ │ └── performance.md │ │ │ └── pkg │ │ │ ├── classes │ │ │ ├── petitiorequest.petitiorequest-1.md │ │ │ └── petitioresponse.petitioresponse-1.md │ │ │ ├── index.md │ │ │ ├── interfaces │ │ │ └── petitiorequest.timeoutoptions.md │ │ │ ├── modules.md │ │ │ └── modules │ │ │ ├── petitio.md │ │ │ ├── petitiorequest.md │ │ │ └── petitioresponse.md │ │ └── docusaurus-theme-classic │ │ ├── footer.json │ │ └── navbar.json ├── package-lock.json ├── package.json ├── sidebars.js ├── src │ ├── components │ │ ├── feature.jsx │ │ ├── feature.module.css │ │ └── version.jsx │ ├── css │ │ └── custom.css │ ├── lib │ │ └── clsx.js │ └── pages │ │ ├── index.jsx │ │ ├── index.module.css │ │ └── versions.jsx ├── static │ ├── .nojekyll │ └── img │ │ ├── docusaurus.png │ │ ├── favicon.ico │ │ ├── logo.svg │ │ ├── undraw_docusaurus_mountain.svg │ │ ├── undraw_docusaurus_react.svg │ │ └── undraw_docusaurus_tree.svg ├── versioned_docs │ └── version-1.2.0 │ │ ├── assets │ │ ├── axios.svg │ │ ├── got.svg │ │ ├── isomorphic-fetch.svg │ │ ├── node-fetch.svg │ │ ├── petitio.svg │ │ ├── phin.svg │ │ ├── r2.svg │ │ ├── request.svg │ │ └── superagent.svg │ │ ├── guides │ │ └── getting-started.md │ │ ├── index.md │ │ ├── metrics │ │ └── performance.md │ │ └── pkg │ │ ├── classes │ │ ├── petitiorequest.petitiorequest-1.md │ │ └── petitioresponse.petitioresponse-1.md │ │ ├── index.md │ │ ├── interfaces │ │ └── petitiorequest.timeoutoptions.md │ │ ├── modules.md │ │ └── modules │ │ ├── petitio.md │ │ ├── petitiorequest.md │ │ └── petitioresponse.md ├── versioned_sidebars │ └── version-1.2.0-sidebars.json └── versions.json ├── esbuild.config.js ├── jest.config.ts ├── package-lock.json ├── package.json ├── release.config.js ├── src ├── index.ts ├── lib │ ├── PetitioRequest.ts │ └── PetitioResponse.ts └── tsconfig.json ├── tests ├── PetitioRequest.test.ts ├── PetitioResponse.test.ts ├── global-setup.ts ├── global-teardown.ts ├── parseHeaders.test.ts └── tsconfig.json ├── tsconfig.eslint.json └── tsconfig.json /.benchmarks/output.txt: -------------------------------------------------------------------------------- 1 | petitio - base x 12,061 ops/sec ±3.79% (279 runs sampled) 2 | 3 | petitio - large body x 497 ops/sec ±3.18% (272 runs sampled) 4 | 5 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@kludge-cs/eslint-config-ts", 3 | "parserOptions": { 4 | "project": "./tsconfig.eslint.json", 5 | "ecmaVersion": 2015 6 | }, 7 | "rules": { 8 | "lines-between-class-members": 0, 9 | "max-len": [2, {"tabWidth": 4, "code": 120, "ignoreComments": true}], 10 | "@typescript-eslint/init-declarations": 0, 11 | "no-underscore-dangle": 0, 12 | "no-extra-parens": 0, 13 | "lines-around-comment": 0 14 | }, 15 | "overrides": [ 16 | { 17 | "files": ["tests/**/*.ts"], 18 | "rules": { 19 | "max-lines-per-function": 0, 20 | "no-duplicate-imports": 0 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report an issue 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Bug Description 11 | 12 | 13 | 14 | ## Reproducible By 15 | 16 | 17 | 18 | ## Expected Behavior 19 | 20 | 21 | 22 | ## Logs & Screenshots 23 | 24 | 26 | 27 | ## Environment 28 | 29 | 31 | 32 | ### Additional context 33 | 34 | 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Make a suggestion on a feature or improvement for the project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## This would solve... 11 | 12 | 14 | 15 | ## The implementation should look like... 16 | 17 | 19 | 20 | ## I have also considered... 21 | 22 | 24 | 25 | ## Additional context 26 | 27 | 29 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/template.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ## This relates to... 12 | 13 | 14 | 15 | ## Rationale 16 | 17 | 19 | 20 | ## Changes 21 | 22 | 23 | 24 | ### Features 25 | 26 | 27 | 28 | ### Bug Fixes 29 | 30 | 31 | 32 | ### Breaking Changes and Deprecations 33 | 34 | 36 | 37 | ## Status 38 | 39 | KEY: S = Skipped, x = complete 40 | 41 | - [ ] Tested 42 | - [ ] Benchmarked (**optional**) 43 | - [ ] Documented 44 | - [ ] Review ready 45 | - [ ] In review 46 | - [ ] Merge ready 47 | -------------------------------------------------------------------------------- /.github/workflows/cd-document.yml: -------------------------------------------------------------------------------- 1 | name: "CD: Document" 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | release: 10 | types: [created] 11 | jobs: 12 | test: 13 | name: Build Documentation 14 | if: github.event_name == 'pull_request' 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | node: [14] 19 | steps: 20 | - name: "[INIT] Checkout repository" 21 | uses: actions/checkout@v2 22 | with: 23 | fetch-depth: 0 24 | - name: "[INIT] Setup Node.js ${{ matrix.node }}" 25 | uses: actions/setup-node@v2 26 | with: 27 | node-version: ${{ matrix.node }} 28 | - name: "[INIT] Restore main dependency cache" 29 | id: main-cache-restore 30 | uses: actions/cache@v2 31 | with: 32 | path: node_modules 33 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 34 | - name: "[INIT] Install main dependencies" 35 | if: ${{ !steps.main-cache-restore.outputs.cache-hit }} 36 | run: npm ci 37 | - name: "[INIT] Restore docs dependency cache" 38 | id: docs-cache-restore 39 | uses: actions/cache@v2 40 | with: 41 | path: docs/node_modules 42 | key: ${{ runner.os }}-node${{ matrix.node }}-docs${{ hashFiles('**/package-lock.json') }} 43 | - name: "[INIT] Install docs dependencies" 44 | if: ${{ !steps.docs-cache-restore.outputs.cache-hit }} 45 | run: npm ci 46 | working-directory: ./docs 47 | - name: "[EXEC] Build documentation" 48 | run: npm run build 49 | working-directory: ./docs 50 | deploy: 51 | name: Deploy to GitHub Pages 52 | if: github.event_name == 'push' 53 | runs-on: ubuntu-latest 54 | strategy: 55 | matrix: 56 | node: [14] 57 | steps: 58 | - name: "[INIT] Checkout repository" 59 | uses: actions/checkout@v2 60 | - name: "[INIT] Setup Node.js ${{ matrix.node }}" 61 | uses: actions/setup-node@v2 62 | with: 63 | node-version: ${{ matrix.node }} 64 | - name: "[INIT] Restore main dependency cache" 65 | id: main-cache-restore 66 | uses: actions/cache@v2 67 | with: 68 | path: node_modules 69 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 70 | - name: "[INIT] Install main dependencies" 71 | if: ${{ !steps.main-cache-restore.outputs.cache-hit }} 72 | run: npm ci 73 | - name: "[INIT] Restore docs dependency cache" 74 | id: docs-cache-restore 75 | uses: actions/cache@v2 76 | with: 77 | path: docs/node_modules 78 | key: ${{ runner.os }}-node${{ matrix.node }}-docs${{ hashFiles('**/package-lock.json') }} 79 | - name: "[INIT] Install docs dependencies" 80 | if: ${{ !steps.docs-cache-restore.outputs.cache-hit }} 81 | run: npm ci 82 | working-directory: ./docs 83 | - name: "[INIT] Setup ssh-agent" 84 | uses: webfactory/ssh-agent@v0.5.2 85 | with: 86 | ssh-private-key: ${{ secrets.GH_PAGES_DEPLOY }} 87 | - name: "[EXEC] Deploy documentation" 88 | run: | 89 | git config --global user.name 'Kludge Cyber Systems (CI)' 90 | git config --global user.email contact@kludge-cs.co.uk 91 | npm run deploy 92 | working-directory: ./docs 93 | env: 94 | USE_SSH: true 95 | GIT_USER: kludge-cs 96 | version-deploy: 97 | name: Version for Release & Deploy to GitHub Pages 98 | if: github.event_name == 'release' 99 | runs-on: ubuntu-latest 100 | strategy: 101 | matrix: 102 | node: [14] 103 | steps: 104 | - name: "[INIT] Checkout repository" 105 | uses: actions/checkout@v2 106 | - name: "[INIT] Setup Node.js ${{ matrix.node }}" 107 | uses: actions/setup-node@v2 108 | with: 109 | node-version: ${{ matrix.node }} 110 | - name: "[INIT] Restore main dependency cache" 111 | id: main-cache-restore 112 | uses: actions/cache@v2 113 | with: 114 | path: node_modules 115 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 116 | - name: "[INIT] Install main dependencies" 117 | if: ${{ !steps.main-cache-restore.outputs.cache-hit }} 118 | run: npm ci 119 | - name: "[INIT] Restore docs dependency cache" 120 | id: docs-cache-restore 121 | uses: actions/cache@v2 122 | with: 123 | path: docs/node_modules 124 | key: ${{ runner.os }}-node${{ matrix.node }}-docs${{ hashFiles('**/package-lock.json') }} 125 | - name: "[INIT] Install docs dependencies" 126 | if: ${{ !steps.docs-cache-restore.outputs.cache-hit }} 127 | run: npm ci 128 | working-directory: ./docs 129 | - name: "[INIT] Setup ssh-agent" 130 | uses: webfactory/ssh-agent@v0.5.2 131 | with: 132 | ssh-private-key: ${{ secrets.GH_PAGES_DEPLOY }} 133 | - name: "[EXEC] Version & deploy documentation" 134 | run: | 135 | git config --global user.name 'Kludge Cyber Systems (CI)' 136 | git config --global user.email contact@kludge-cs.co.uk 137 | PACKAGE_VERSION=$(node -pe "require('../package.json').version") 138 | npm run docusaurus docs:version $PACKAGE_VERSION 139 | for locale in $(ls i18n); do 140 | mkdir -p i18n/$locale/docusaurus-plugin-content-docs/$PACKAGE_VERSION 141 | cp -r docs/* i18n/$locale/docusaurus-plugin-content-docs/$PACKAGE_VERSION 142 | done 143 | git add . 144 | git commit -m "docs: add version $PACKAGE_VERSION" 145 | git push || true 146 | npm run deploy 147 | working-directory: ./docs 148 | env: 149 | USE_SSH: true 150 | GIT_USER: kludge-cs 151 | -------------------------------------------------------------------------------- /.github/workflows/cd-release.yml: -------------------------------------------------------------------------------- 1 | name: "CD: Release" 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | release: 8 | name: Release 9 | if: "(contains(github.event.head_commit.message, '[ci_release]'))" 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | node: [14] 14 | steps: 15 | - name: "[INIT] Checkout repository" 16 | uses: actions/checkout@v2 17 | with: 18 | fetch-depth: 0 19 | - name: "[INIT] Setup Node.js ${{ matrix.node }}" 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: ${{ matrix.node }} 23 | - name: "[INIT] Restore dependency cache" 24 | id: cache-restore 25 | uses: actions/cache@v2 26 | with: 27 | path: node_modules 28 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 29 | - name: "[INIT] Install dependencies" 30 | if: ${{ !steps.cache-restore.outputs.cache-hit }} 31 | run: npm ci 32 | - name: "[EXEC] Release" 33 | run: | 34 | npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN 35 | npx semantic-release 36 | env: 37 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 39 | GIT_AUTHOR_NAME: Kludge Cyber Systems (CI) 40 | GIT_AUTHOR_EMAIL: contact@kludge-cs.co.uk 41 | GIT_COMMITTER_NAME: Kludge Cyber Systems (CI) 42 | GIT_COMMITTER_EMAIL: contact@kludge-cs.co.uk 43 | - name: "[POST] Clean up failed release" 44 | if: failure() 45 | run: git reset HEAD^ && git push --force 46 | -------------------------------------------------------------------------------- /.github/workflows/ci-benchmark.yml: -------------------------------------------------------------------------------- 1 | name: "CI: Benchmark" 2 | on: [pull_request] 3 | jobs: 4 | benchmark: 5 | name: Benchmark 6 | if: "!(contains(github.event.head_commit.message, '[skip_ci]'))" 7 | runs-on: ubuntu-latest 8 | defaults: 9 | run: 10 | shell: bash 11 | strategy: 12 | matrix: 13 | node: [14] 14 | steps: 15 | - name: "[INIT] Checkout repository" 16 | uses: actions/checkout@v2 17 | with: 18 | fetch-depth: 0 19 | - name: "[INIT] Setup Node.js ${{ matrix.node }}" 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: ${{ matrix.node }} 23 | - name: "[INIT] Restore dependency cache" 24 | id: cache-restore 25 | uses: actions/cache@v2 26 | with: 27 | path: node_modules 28 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 29 | - name: "[INIT] Install dependencies" 30 | if: ${{ !steps.cache-restore.outputs.cache-hit }} 31 | run: npm ci 32 | - name: "[INIT] Build" 33 | run: npm run build 34 | - name: "[INIT] Download previous benchmark data" 35 | uses: actions/cache@v1 36 | with: 37 | path: ./cache 38 | key: ${{ runner.os }}-benchmark 39 | - name: "[EXEC] Benchmark" 40 | run: npm run --silent bench | tee .benchmarks/output.txt 41 | - name: "[POST] Store benchmark results" 42 | uses: rhysd/github-action-benchmark@v1 43 | with: 44 | name: Petitio 45 | tool: "benchmarkjs" 46 | output-file-path: .benchmarks/output.txt 47 | external-data-json-path: ./cache/benchmark-data.json 48 | alert-threshold: "200%" 49 | github-token: ${{ secrets.GITHUB_TOKEN }} 50 | alert-comment-cc-users: "@tbnritzdoge @nytelife26" 51 | comment-on-alert: true 52 | fail-on-alert: true 53 | - name: "[POST] Push benchmark results" 54 | if: github.event_name != 'pull_request' 55 | run: | 56 | git config user.name 'Kludge Cyber Systems (CI)' 57 | git config user.email contact@kludge-cs.co.uk 58 | git add .benchmarks 59 | git commit --no-verify -m 'chore: update benchmarks' || true 60 | git push 61 | env: 62 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 63 | -------------------------------------------------------------------------------- /.github/workflows/ci-build.yml: -------------------------------------------------------------------------------- 1 | name: "CI: Build" 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | build: 8 | name: Build 9 | if: "!(contains(github.event.head_commit.message, '[skip_ci]'))" 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | node: [14] 14 | steps: 15 | - name: "[INIT] Checkout repository" 16 | uses: actions/checkout@v2 17 | with: 18 | fetch-depth: 0 19 | - name: "[INIT] Setup Node.js ${{ matrix.node }}" 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: ${{ matrix.node }} 23 | - name: "[INIT] Restore dependency cache" 24 | id: cache-restore 25 | uses: actions/cache@v2 26 | with: 27 | path: node_modules 28 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 29 | - name: "[INIT] Install dependencies" 30 | if: ${{ !steps.cache-restore.outputs.cache-hit }} 31 | run: npm ci 32 | - name: "[EXEC] Build" 33 | run: npm run build 34 | - name: "[EXEC] Update build branch" 35 | run: | 36 | git pull || true 37 | git config --global user.name 'Kludge Cyber Systems (CI)' 38 | git config --global user.email contact@kludge-cs.co.uk 39 | mkdir $GITHUB_WORKSPACE/../transfer 40 | PACKAGE_VERSION=$(node -pe "require('./package.json').version") 41 | npm pack 42 | cp *.tgz $GITHUB_WORKSPACE/../transfer 43 | if [[ $(git checkout build) ]]; then 44 | echo -e "# Using existing build" 45 | git restore --staged . || true 46 | else 47 | echo -e "# Creating orphan build" 48 | git checkout --orphan build 49 | git rm --cached -r . 50 | git commit --allow-empty -m 'chore: initial commit' || true 51 | fi 52 | git clean -fdx && git reset --hard HEAD 53 | git rm -rf . && cp -r $GITHUB_WORKSPACE/../transfer/*.tgz ./ 54 | tar -xf *.tgz && rm *.tgz 55 | mv ./package/* . 56 | rm -rf package 57 | git add . 58 | git commit -m "build: v${PACKAGE_VERSION}" || true 59 | git push --set-upstream origin build 60 | env: 61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 62 | -------------------------------------------------------------------------------- /.github/workflows/ci-codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CI: CodeQL Analysis" 2 | on: [push, pull_request] 3 | jobs: 4 | analyze: 5 | name: Analyze JavaScript 6 | runs-on: ubuntu-latest 7 | strategy: 8 | fail-fast: false 9 | matrix: 10 | language: [javascript] 11 | steps: 12 | - name: "[INIT] Checkout repository" 13 | uses: actions/checkout@v2 14 | - name: "[INIT] Set up CodeQL" 15 | uses: github/codeql-action/init@v1 16 | with: 17 | languages: ${{ matrix.language }} 18 | - name: "[EXEC] Perform analysis" 19 | uses: github/codeql-action/analyze@v1 20 | -------------------------------------------------------------------------------- /.github/workflows/ci-lint-test.yml: -------------------------------------------------------------------------------- 1 | name: "CI: Lint & Test" 2 | on: [push, pull_request] 3 | jobs: 4 | eslint: 5 | name: Lint 6 | if: "!(contains(github.event.head_commit.message, '[skip_ci]'))" 7 | runs-on: ubuntu-latest 8 | defaults: 9 | run: 10 | shell: bash 11 | strategy: 12 | matrix: 13 | node: [14] 14 | steps: 15 | - name: "[INIT] Checkout repository" 16 | uses: actions/checkout@v2 17 | - name: "[INIT] Install Node.js ${{ matrix.node }}" 18 | uses: actions/setup-node@v2 19 | with: 20 | node-version: ${{ matrix.node }} 21 | - name: "[INIT] Restore dependency cache" 22 | id: cache-restore 23 | uses: actions/cache@v2 24 | with: 25 | path: node_modules 26 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 27 | - name: "[INIT] Install dependencies" 28 | if: ${{ !steps.cache-restore.outputs.cache-hit }} 29 | run: npm ci 30 | - name: "[EXEC] Lint" 31 | run: npm run lint 32 | - name: "[EXEC] Push lint fixes" 33 | run: | 34 | git config user.name 'Kludge Cyber Systems (CI)' 35 | git config user.email contact@kludge-cs.co.uk 36 | git add . 37 | if git commit --no-verify -m 'style: apply lint'; then 38 | if [[ '${{ github.head_ref }}' ]]; then 39 | git push origin HEAD:${{ github.head_ref }} 40 | else 41 | git push 42 | fi 43 | fi 44 | env: 45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 46 | test-cover: 47 | name: Test & Upload Coverage 48 | if: "!(contains(github.event.head_commit.message, '[skip_ci]'))" 49 | runs-on: ubuntu-latest 50 | defaults: 51 | run: 52 | shell: bash 53 | strategy: 54 | matrix: 55 | node: [12, 14, 16] 56 | steps: 57 | - name: "[INIT] Checkout repository" 58 | uses: actions/checkout@v2 59 | - name: "[INIT] Install Node.js ${{ matrix.node }}" 60 | uses: actions/setup-node@v2 61 | with: 62 | node-version: ${{ matrix.node }} 63 | - name: "[INIT] Restore dependency cache" 64 | id: cache-restore 65 | uses: actions/cache@v2 66 | with: 67 | path: node_modules 68 | key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} 69 | - name: "[INIT] Install dependencies" 70 | if: ${{ !steps.cache-restore.outputs.cache-hit }} 71 | run: npm ci 72 | - name: "[EXEC] Test" 73 | run: npm run test:coverage 74 | - name: "[EXEC] Upload coverage to Coveralls" 75 | uses: coverallsapp/github-action@v1.1.2 76 | with: 77 | github-token: ${{ secrets.GITHUB_TOKEN }} 78 | flag-name: run-node${{ matrix.node }} 79 | parallel: true 80 | cover: 81 | name: Finalize Coverage Report 82 | if: "!(contains(github.event.head_commit.message, '[skip_ci]'))" 83 | needs: test-cover 84 | runs-on: ubuntu-latest 85 | steps: 86 | - name: "[POST] Finalize Coveralls collection" 87 | uses: coverallsapp/github-action@v1.1.2 88 | with: 89 | github-token: ${{ secrets.GITHUB_TOKEN }} 90 | parallel-finished: true 91 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | coverage 4 | .husky/_ 5 | .husky/.gitignore 6 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | [ -n "$CI" ] && exit 0 5 | npx lint-staged && npx jest -o 6 | -------------------------------------------------------------------------------- /.lintstagedrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "*.ts": "eslint --fix", 3 | "tests/**/*.ts": "jest" 4 | } 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [1.4.0](https://github.com/helperdiscord/petitio/compare/v1.3.2...v1.4.0) (2021-10-15) 2 | 3 | 4 | ### Features 5 | 6 | * release [ci_release] ([3ceba21](https://github.com/helperdiscord/petitio/commit/3ceba21006ce0f689f97f63dad4f3852d7fb52d3)) 7 | 8 | ## [1.3.2](https://github.com/helperdiscord/petitio/compare/v1.3.1...v1.3.2) (2021-05-13) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * master -> main [ci_release] ([a0dafd6](https://github.com/helperdiscord/petitio/commit/a0dafd656349e6df692208e28033afcc837da77e)) 14 | 15 | ## [1.3.1](https://github.com/helperdiscord/petitio/compare/v1.3.0...v1.3.1) (2021-04-21) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * support node 16 [ci_release] ([#28](https://github.com/helperdiscord/petitio/issues/28)) ([9d4dec5](https://github.com/helperdiscord/petitio/commit/9d4dec59f44d44742c765de6fc53c03aa4343e89)) 21 | 22 | # [1.3.0](https://github.com/helperdiscord/petitio/compare/v1.2.1...v1.3.0) (2021-04-13) 23 | 24 | 25 | ### Bug Fixes 26 | 27 | * change build target for backwards compat ([#25](https://github.com/helperdiscord/petitio/issues/25)) ([87cbbd3](https://github.com/helperdiscord/petitio/commit/87cbbd34851f132870e819d34d70bf032f7bde6f)) 28 | * **ci:** make filepaths correct ([9299fc0](https://github.com/helperdiscord/petitio/commit/9299fc00137be6ea195d93c871395f22fd579196)) 29 | 30 | 31 | ### Features 32 | 33 | * abort-controllers ([#23](https://github.com/helperdiscord/petitio/issues/23)) ([1ad4a5d](https://github.com/helperdiscord/petitio/commit/1ad4a5d86044d3dd77c8234703189c162fe93134)) 34 | * add all http methods ([#17](https://github.com/helperdiscord/petitio/issues/17)) ([f869666](https://github.com/helperdiscord/petitio/commit/f869666169a39c5f0baacc48d23b48c6a6073163)) 35 | * **ci:** build on every commit ([443070b](https://github.com/helperdiscord/petitio/commit/443070b8b09a9b6b087f634bf16ab4d69c0f8783)) 36 | 37 | 38 | ### Performance Improvements 39 | 40 | * improve response buffer handling ([#20](https://github.com/helperdiscord/petitio/issues/20)) ([26d84e2](https://github.com/helperdiscord/petitio/commit/26d84e22d88359869a747c0828e4d21e0fbdce95)) 41 | * optimize loops ([#24](https://github.com/helperdiscord/petitio/issues/24)) ([01b8012](https://github.com/helperdiscord/petitio/commit/01b80124bd8baa89e9b8ee4e40987c0cba1e57b8)) 42 | 43 | ## [1.2.1](https://github.com/helperdiscord/petitio/compare/v1.2.0...v1.2.1) (2021-04-07) 44 | 45 | 46 | ### Bug Fixes 47 | 48 | * **docs:** new baseUrl ([cc50d17](https://github.com/helperdiscord/petitio/commit/cc50d176ad14f2ca10a865c3eb0ed7d2b511f84a)) 49 | 50 | # [1.2.0](https://github.com/helperdiscord/petitio/compare/v1.1.0...v1.2.0) (2021-04-07) 51 | 52 | 53 | ### Bug Fixes 54 | 55 | * **PetitioResponse:** support non-ascii json responses ([#11](https://github.com/helperdiscord/petitio/issues/11)) ([d8344e4](https://github.com/helperdiscord/petitio/commit/d8344e44bb2ca247082c7f330354a76869e49793)) 56 | 57 | 58 | ### Features 59 | 60 | * add support for stream ([c706801](https://github.com/helperdiscord/petitio/commit/c7068011464ce003d4443ab975b48bab9b0ac74f)) 61 | * add text encoding option & tests ([7f6f5c6](https://github.com/helperdiscord/petitio/commit/7f6f5c63f3dddc2838c7dc1975c8a5c9335f120d)) 62 | 63 | 64 | ### Performance Improvements 65 | 66 | * remove spread operators and callback loops ([#12](https://github.com/helperdiscord/petitio/issues/12)) ([3bf48cc](https://github.com/helperdiscord/petitio/commit/3bf48cc1d002fb342af932f720dfc833c94461fe)) 67 | 68 | # [1.1.0](https://github.com/helperdiscord/petitio/compare/v1.0.0...v1.1.0) (2021-03-22) 69 | 70 | 71 | ### Features 72 | 73 | * add _parseHeaders to PetitioResponse ([188bf94](https://github.com/helperdiscord/petitio/commit/188bf94cafa4df4f54f5354fa8b42313aace6e0d)) 74 | * add docs and adjust types [ci_release] ([76e8bf9](https://github.com/helperdiscord/petitio/commit/76e8bf92dfbe9c6aae18b76412024ba6897271e8)) 75 | * **ci:** test workflow ([c8e101d](https://github.com/helperdiscord/petitio/commit/c8e101d91f8c41f016ff630c663b6367b748c4b6)) 76 | * **tests:** 100% coverage :rocket: ([27d9f0b](https://github.com/helperdiscord/petitio/commit/27d9f0bae2cbbf51b6a1c8b8cd9fda0fccc1cdd4)) 77 | * **tests:** finalize petitioresponse tests ([e0a770a](https://github.com/helperdiscord/petitio/commit/e0a770ad7f7a6ccbdcc0d240282de040c9869c36)) 78 | * add client method ([b257087](https://github.com/helperdiscord/petitio/commit/b257087d3d92412857de2f0c733050b4f16a6c52)) 79 | * proper import mapping ([410e534](https://github.com/helperdiscord/petitio/commit/410e53457e7dcd87ed5f4f0bd6f536a0b66d547b)) 80 | * type the dispatch funcs ([c630078](https://github.com/helperdiscord/petitio/commit/c630078330877f46dd4dea6a4edb25b99753fd81)) 81 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to any repositories maintained by or falling under the scope 4 | of Kludge Cyber Systems (hereon referred to as KCS), please first discuss the 5 | change you wish to make via issue, email, or any other method with the 6 | maintainer of the repository or lead members of the team the repository falls 7 | under before making a change (this does not apply if you are an external 8 | contributor submitting a pull request for a fork). 9 | 10 | Note that we have a code of conduct (see [below][coc]) - please follow it in all 11 | your interactions with the project. 12 | 13 | [coc]: CONTRIBUTING.md#code-of-conduct 14 | 15 | ## Pull Request Process 16 | 17 | 1. Ensure any dependencies are updated to be as recent as possible, and all 18 | security issues are audited. Optionally, Depfu will do this for you. 19 | 2. Ensure the branch passes all checks (especially lint and tests) and your 20 | contribution follows all our guidelines. 21 | 3. Update the CHANGELOG.md with details of changes and who authored them, except 22 | in repositories that make use of the automatic release workflow. 23 | 4. Increment the version numbers in any example files, README.md, and 24 | CHANGELOG.md to the new version that this Pull Request would represent. 25 | The versioning scheme we use is [semantic versioning][semver]. Once again, 26 | this is not necessary for repositories that use the automatic release 27 | workflow. 28 | 5. You may merge the Pull Request if any of the following are true (and, if you 29 | cannot merge yourself, you may ask the most recent reviewing contributor to 30 | do it for you): 31 | * *a)* The contributions are on `staging` targeted at `master`, the source 32 | has been tested properly and passes all workflows *AND* has the approval of 33 | two organization members. 34 | * *b)* The contribution is on a `dev/*` branch targeted at `staging` and your 35 | code passes all tests and workflows. 36 | * *c)* The contribution is from an external branch targeted at `staging` and 37 | your code passes all tests and workflows. 38 | 39 | [semver]: https://semver.org 40 | 41 | ## Standard of Work 42 | 43 | This section is dedicated to laying out general rules for contributing to any 44 | KCS project. If the repository you are working on has its own style guide, it 45 | overrides this one. Else, all of these guidelines apply. For further 46 | information, consult the respective lint configurations. 47 | 48 | ### Licensing 49 | 50 | As per our license of choice, the [MIT license][license], compatibility checking 51 | is largely not necessary. As long as our copyright header is included in 52 | derivative works, and libraries are under compatible licenses (which is most of 53 | them due to the nature of the MIT license), all is fine. 54 | 55 | While you may be tempted to use our design philosophy to perpetuate restrictions 56 | on which libraries are used, such as favouring those under similar licenses, 57 | this practice is discouraged - education and discussion is preferred to cutting 58 | usage of valuable and often superlative libraries based solely on their 59 | licensing rather than quality. 60 | 61 | [license]: LICENSE 62 | 63 | ### Formatting 64 | 65 | * Tabs for indentation, spaces for formatting. 66 | * UNIX style newlines. 67 | * Trim all trailing whitespace. 68 | * Use semicolons at the end of every statement (but not after function or class 69 | declarations). 70 | * 80 characters per line of source code. 71 | * Use string formatting instead of concatenation. 72 | * Use the language-specific templating for strings with formatting, and double 73 | quotes for no formatting. 74 | * Block declaration braces go on the same line as the condition or declarative 75 | statement. 76 | * Declare only one variable per declarative statement, rather than *comma 77 | separating. 78 | 79 | ### Array and Object Declaration 80 | 81 | * Use trailing commas. 82 | * Do not put spaces in keys for objects. 83 | * Do not wrap key names in quotes unless necessary (and if necessary, do it 84 | consistently on a per-file basis). 85 | 86 | ### Conditionals 87 | 88 | * Use descriptive conditionality variables for complex conditions rather than 89 | writing their full form. 90 | 91 | ### Functions 92 | 93 | * Keep functions at a minimal length, and create other functions to avoid 94 | complication. 95 | * Make return statements clear and return as early as possible. 96 | * Use one method per line when chaining, and indent them one level further than 97 | the original object. 98 | 99 | ### Comments 100 | 101 | * Only use comments for parser / engine runtime statements or to clarify complex 102 | segments of code. 103 | 104 | ## Code of Conduct 105 | 106 | ### Preface, and Our Philosophy 107 | 108 | KCS projects follow N26's design and scientific philosophy, adapted and deriving 109 | from the initial UNIX philosophy. As such, this statement is one we hold to our 110 | core: **Irrational prejudice and abstract discrimination has no place in 111 | science.** We are not interested in the abstract personal attributes of our 112 | contributors, merely their skill and reasoning as scientists, and the quality of 113 | their work. 114 | 115 | ### Our Pledge 116 | 117 | We as members, contributors, and leaders pledge to make participation in our 118 | community a harassment-free experience for everyone, regardless of personal 119 | background. The only thing that sets us apart as scientists is our ability to 120 | problem-solve, rise to the challenges we are faced with, and work with the 121 | information at hand. 122 | 123 | We pledge to act and interact in ways that contribute to an open, welcoming, 124 | diverse, inclusive, and healthy community. 125 | 126 | ### Our Standards 127 | 128 | Examples of behavior that contributes to a positive environment for our 129 | community include: 130 | 131 | * Demonstrating respect and civility towards other people 132 | * Being respectful of differing opinions, viewpoints, and experiences 133 | * Giving and gracefully accepting constructive feedback 134 | * Accepting accountability for our actions and acknowledging our mistakes 135 | * Focusing on what is best not just for us as individuals, but for the 136 | overall community 137 | 138 | Examples of unacceptable behavior include: 139 | 140 | * The use of sexualized language or imagery, and sexual attention or 141 | advances of any kind 142 | * Trolling, insulting or derogatory comments, and personal or political attacks 143 | * Public or private harassment 144 | * Publishing others' private information, such as a physical or email 145 | address, without their explicit permission 146 | * Other conduct which could reasonably be considered inappropriate in a 147 | professional setting 148 | 149 | ### Enforcement Responsibilities 150 | 151 | Community leaders are responsible for clarifying and enforcing our standards of 152 | acceptable behavior and will take appropriate and fair corrective action in 153 | response to any behavior that they deem harmful within the boundaries of reason. 154 | 155 | Community leaders have the right and responsibility to remove, edit, or reject 156 | comments, commits, code, wiki edits, issues, and other contributions that do not 157 | follow this Code of Conduct, and will communicate reasons for moderation 158 | decisions when appropriate or upon request. 159 | 160 | Note that it is important to us that we are not perpetuators of censorship; 161 | rather, we seek only to establish an environment that reasonably enables 162 | everyone to work comfortably. We vow to not overstep boundaries or punish people 163 | based solely on our personal beliefs, and instead to act with rational and 164 | appropriate response. 165 | 166 | ### Scope 167 | 168 | This Code of Conduct applies within all community spaces, and also applies when 169 | an individual is officially representing the community in public spaces. 170 | Examples of representing our community include using an official e-mail address, 171 | posting via an official social media account, or acting as an appointed 172 | representative at an online or offline event. 173 | 174 | An individual's personal life is not bound to their career image, and we impose 175 | no requirements for their conduct out of our field. However, if one's personal 176 | image directly ties to their professional image, id est if their personal 177 | platforms are under the same alias they use to work with us, we reserve the 178 | right to impose necessary sanctions or restrictions in order to protect our 179 | image as a development community from being tarnished by their personal actions. 180 | 181 | ### Enforcement 182 | 183 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 184 | reported to the community leaders responsible for enforcement. All complaints 185 | will be reviewed and investigated promptly and fairly. 186 | 187 | All community leaders are obligated to respect the privacy and security of the 188 | reporter of any incident. 189 | 190 | ### Attribution 191 | 192 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 193 | version 2.0, available [here][version]. A large portion of this document has 194 | been edited, so take care with translations as they are not reflective of this 195 | document, but rather the work from which it derived. 196 | 197 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 198 | enforcement ladder](https://github.com/mozilla/diversity). 199 | 200 | For answers to common questions about this code of conduct, see the [FAQ][faq]. 201 | [Translations][translations] are also available. 202 | 203 | [homepage]: https://www.contributor-covenant.org 204 | [version]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html 205 | [faq]: https://www.contributor-covenant.org/faq 206 | [translations]: https://www.contributor-covenant.org/translations 207 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020, Helperdiscord 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /PERFORMANCE.md: -------------------------------------------------------------------------------- 1 | # Package size 2 | 3 | Here you can see how efficient `petito` is as opposed to other 4 | libraries, in terms of bundle size. 5 | 6 | | Package | Size | 7 | |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| 8 | | request | [](https://packagephobia.now.sh/result?p=request) | 9 | | superagent | [](https://packagephobia.now.sh/result?p=superagent) | 10 | | got | [](https://packagephobia.now.sh/result?p=got) | 11 | | axios | [](https://packagephobia.now.sh/result?p=axios) | 12 | | isomorphic-fetch | [](https://packagephobia.now.sh/result?p=isomorphic-fetch) | 13 | | r2 | [](https://packagephobia.now.sh/result?p=r2) | 14 | | node-fetch | [](https://packagephobia.now.sh/result?p=node-fetch) | 15 | | phin | [](https://packagephobia.now.sh/result?p=phin) | 16 | | petitio | [](https://packagephobia.now.sh/result?p=petitio) | 17 | 18 | # Performance 19 | 20 | If you wish to verify these results, you may run [the suite] yourself. 21 | You can find the results [here]. 22 | 23 | [the suite]: https://github.com/helperdiscord/http-benchmarks 24 | [here]: https://github.com/helperdiscord/http-benchmarks/blob/main/RESULTS.md 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # petitio 2 | 3 | A zero-dependency HTTP library designed to be simple, fast, and type-strong. 4 | 5 | Credit to [Centra] for inspiration, as Petitio was originally a fork. 6 | 7 | [Centra]: https://github.com/ethanent/centra 8 | 9 | Useful links: 10 | - [Docs](https://helperdiscord.github.io/petitio) 11 | - [Usage examples](https://github.com/helperdiscord/petitio/tree/master/USAGE.md) 12 | - [Benchmarks / comparison](https://github.com/helperdiscord/petitio/tree/master/PERFORMANCE.md) 13 | 14 | ## What's with the name? 15 | 16 | *"Petitio"* is a hybrid between the French word for "small" ("petit"), and the 17 | Latin word for "request" ("petitio"). This library was originally called 18 | `@helperdiscord/centra`, but we changed it to evolve beyond our status as a 19 | Centra fork and set out to create the smallest and fastest high-level Node HTTP 20 | wrapper available. 21 | -------------------------------------------------------------------------------- /benchmarks/client.mjs: -------------------------------------------------------------------------------- 1 | import { CycleLogger } from "@kludge-cs/bench-utils"; 2 | // @ts-expect-error: BenchmarkJS does not support ESM exports 3 | import bench from "benchmark"; 4 | const { Suite } = bench; 5 | // @ts-expect-error: TSC is not aware when petitio is built 6 | import petitio from "../dist/index.mjs"; 7 | import undici from "undici"; 8 | const { Client } = undici; 9 | 10 | const client = new Client("http://localhost:8080"); 11 | const defer = {"defer": true, "minSamples": 200}; 12 | 13 | new Suite() 14 | .add("petitio - base", async (deferred) => { 15 | await petitio("http://localhost:8080/ok") 16 | .client(client, true) 17 | .send(); 18 | deferred.resolve(); 19 | }, defer) 20 | .add("petitio - large body", async (deferred) => { 21 | await petitio("http://localhost:8080/large") 22 | .client(client, true) 23 | .send(); 24 | deferred.resolve(); 25 | }, defer) 26 | .on("cycle", (event) => console.log(event.target.toString())) 27 | .run({async: true}); 28 | -------------------------------------------------------------------------------- /benchmarks/index.mjs: -------------------------------------------------------------------------------- 1 | import { spawn } from "child_process"; 2 | const server = spawn("node", ["benchmarks/server.mjs"]); 3 | const client = spawn("node", ["benchmarks/client.mjs"]); 4 | 5 | client.stdout.on("data", (data) => console.log(data.toString())); 6 | client.on("error", (err) => console.error(err)); 7 | server.on("error", (err) => console.error(err)); 8 | 9 | client.on("exit", () => server.kill("SIGKILL")); 10 | -------------------------------------------------------------------------------- /benchmarks/server.mjs: -------------------------------------------------------------------------------- 1 | import * as http from "http"; 2 | import { dirname } from "path"; 3 | import { fileURLToPath } from "url"; 4 | import { readFileSync } from "fs"; 5 | 6 | // @ts-expect-error: the file is running as a module, import.meta is allowed 7 | const largeData = readFileSync(`${dirname(fileURLToPath(import.meta.url))}/large.txt`).toString(); 8 | 9 | function requestHandler(req, res) { 10 | switch (req.url) { 11 | case "/ok": { 12 | res.writeHead(200, {"Content-Type": "text/plain"}); 13 | res.end("ok"); 14 | return; 15 | } 16 | case "/large": { 17 | res.writeHead(200, {"Content-Type": "text/plain"}); 18 | res.end(largeData); 19 | return; 20 | } 21 | default: { 22 | res.end("No benchmark specified."); 23 | } 24 | } 25 | } 26 | 27 | http 28 | .createServer(requestHandler) 29 | .listen(8080, () => console.log("Awaiting requests.")); 30 | -------------------------------------------------------------------------------- /docs/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["@kludge-cs/eslint-config-js", "plugin:react/recommended"], 3 | "env": { 4 | "es2021": true, 5 | "browser": true 6 | }, 7 | "parserOptions": { 8 | "ecmaVersion": 12, 9 | "ecmaFeatures": { 10 | "jsx": true 11 | } 12 | }, 13 | "settings": { 14 | "react": { 15 | "version": "17" 16 | } 17 | }, 18 | "rules": { 19 | "node/no-unsupported-features/es-syntax": 0 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | typedoc-sidebar.js 2 | .docusaurus 3 | build 4 | -------------------------------------------------------------------------------- /docs/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve("@docusaurus/core/lib/babel/preset")] 3 | }; 4 | -------------------------------------------------------------------------------- /docs/blog/2021-04-06-welcome.md: -------------------------------------------------------------------------------- 1 | --- 2 | slug: welcome 3 | title: Welcome 4 | author: Tyler J. Russell (Nytelife26) 5 | author_title: CTO & Acting Director of Kludge Cyber Systems 6 | author_url: https://github.com/nytelife26 7 | author_image_url: https://en.gravatar.com/userimage/102587429/5bdfbd099d18c5dc86b905f5d54040bd.jpg?size=800 8 | tags: [welcome, http, getting-started] 9 | --- 10 | 11 | Welcome! This will be my first blog post as a developer of Petitio and for 12 | the new documentation site - exciting times! 13 | 14 | As a collaborative project, Petitio has become the fastest high-level HTTP 15 | library in the Node ecosystem, and one of the first to use undici instead of 16 | native HTTP. 17 | 18 | Our current plans are to implement hooks and then add HTTP/2 support to undici. 19 | 20 | Thank you, and that's all for now. Stay tuned for more. 21 | -------------------------------------------------------------------------------- /docs/docs/assets/axios.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 388 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 388 kB 17 | 388 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/got.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.33 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.33 MB 17 | 1.33 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/isomorphic-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 216 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 216 kB 17 | 216 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/node-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 155 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 155 kB 17 | 155 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/petitio.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 41.2 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 41.2 kB 17 | 41.2 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/phin.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 23.0 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 23.0 kB 17 | 23.0 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/r2.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 201 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 201 kB 17 | 201 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/request.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 3.84 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 3.84 MB 17 | 3.84 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/assets/superagent.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.70 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.70 MB 17 | 1.70 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/docs/guides/basic-examples.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "basic-examples" 3 | title: "Basic Examples" 4 | --- 5 | 6 | # Examples 7 | 8 | ### Basic GET Request 9 | 10 | ```js 11 | const req = require("petitio"); 12 | 13 | const res = await req("https://discord.com/api/gateway").json() 14 | console.log(res); 15 | 16 | // { url: "wss://gateway.discord.gg" } 17 | ``` 18 | 19 | ### Simple POST Request with payload 20 | 21 | ```js 22 | const req = require("petitio"); 23 | 24 | const res = await req("https://discord.com/api/channels/ID/messages", "POST") 25 | .body({ content: "hi" }) 26 | .header({ "Authorization": "Bot TOKEN" }) 27 | .json(); 28 | console.log(res); 29 | 30 | /* { 31 | id: "805925621561163806", 32 | type: 0, 33 | content: "hi", 34 | channel_id: "418933739540840451", 35 | author: [Object], 36 | attachments: [], 37 | embeds: [], 38 | mentions: [], 39 | mention_roles: [], 40 | pinned: false, 41 | mention_everyone: false, 42 | tts: false, 43 | timestamp: "2021-02-01T2220:41.554000+00:00", 44 | edited_timestamp: null, 45 | flags: 0, 46 | referenced_message: null 47 | } */ 48 | ``` 49 | 50 | ### Type casting JSON responses 51 | 52 | ```ts 53 | import req from "petitio"; 54 | 55 | interface Gateway { 56 | url: string; 57 | } 58 | 59 | const res = await req("https://discord.com/api/gateway").json(); 60 | ``` 61 | -------------------------------------------------------------------------------- /docs/docs/guides/getting-started.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "getting-started" 3 | title: "Getting Started" 4 | --- 5 | 6 | **Note: Petitio supports both `require` and `import` syntax out of the box, so 7 | there's no need to do any pesky ESM or CJS hacks.** 8 | 9 | ## Basic Usage 10 | 11 | The [default export] of Petitio is a wrapper function for [PetitioRequest], 12 | meaning all you need to get started is as follows: 13 | 14 | ```typescript 15 | import petitio from "petitio"; 16 | 17 | const request = petitio("https://example.com"); 18 | ``` 19 | 20 | That instantiates a [PetitioRequest] for `example.com`. Simple right? 21 | Let's take a look at how we send requests and work with responses. 22 | 23 | ```typescript 24 | const result = await request.send().text(); 25 | // equivalent to 26 | const result = await request.text(); 27 | ``` 28 | 29 | Fast and clean. Beautiful, even. But how does that work? 30 | [PetitioRequest#send][send] instructs Petitio to send the current 31 | [PetitioRequest] and returns a [PetitioResponse] with the response data, and 32 | then [PetitioResponse#text][response-text] parses the response body from 33 | a buffer to a string. The shorthand form of this is 34 | [PetitioRequest#text][request-text], which sends the request and invokes text 35 | parsing for you in one call. 36 | 37 | That's the basics covered! Feel free to read through our [other 38 | guides], or take a look at more [basic examples]. 39 | 40 | [default export]: ../pkg/modules/petitio#export 41 | [PetitioRequest]: ../pkg/classes/petitiorequest.petitiorequest-1 42 | [PetitioResponse]: ../pkg/classes/petitioresponse.petitioresponse-1 43 | [send]: ../pkg/classes/petitiorequest.petitiorequest-1#send 44 | [response-text]: ../pkg/classes/petitioresponse.petitioresponse-1#text 45 | [request-text]: ../pkg/classes/petitiorequest.petitiorequest-1#text 46 | [other guides]: ../ 47 | [basic examples]: ./basic-examples 48 | -------------------------------------------------------------------------------- /docs/docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "index" 4 | slug: "/" 5 | sidebar_label: "Home" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # Petitio Reference 11 | 12 | Here you will find the documentation for Petitio. 13 | 14 | We suggest you start by checking out the following: 15 | - [The "Getting Started" guide](/docs/guides/getting-started) 16 | - [The API Reference](/docs/pkg) 17 | -------------------------------------------------------------------------------- /docs/docs/metrics/performance.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "performance" 3 | title: "Performance" 4 | --- 5 | 6 | ## Preface 7 | 8 | These results are collected from [a suite] managed by helperdiscord and verified 9 | by Kludge Cyber Systems. Anyone may add to them with the results from their own 10 | system, and they are kept up to date with at least two samples from each 11 | version. 12 | 13 | [a suite]: https://github.com/helperdiscord/http-benchmarks 14 | 15 | ## Package Size 16 | 17 | Here you can see how efficient Petitio is in contrast to its competitors in 18 | terms of bundle size. 19 | 20 | 21 | Results table 22 | 23 | | Package | Size | 24 | |------------------|--------------------------------------------------------------------------------------------------------------------------------| 25 | | request | [](https://packagephobia.now.sh/result?p=request@2.88.2) | 26 | | superagent | [](https://packagephobia.now.sh/result?p=superagent@6.1.0) | 27 | | got | [](https://packagephobia.now.sh/result?p=got@11.8.2) | 28 | | axios | [](https://packagephobia.now.sh/result?p=axios@0.21.1) | 29 | | isomorphic-fetch | [](https://packagephobia.now.sh/result?p=isomorphic-fetch@3.0) | 30 | | r2 | [](https://packagephobia.now.sh/result?p=r2@2.0.1) | 31 | | node-fetch | [](https://packagephobia.now.sh/result?p=node-fetch@2.6.1) | 32 | | petitio | [](https://packagephobia.now.sh/result?p=petitio@1.1.0) | 33 | | phin | [](https://packagephobia.now.sh/result?p=phin@3.5.1) | 34 | 35 | 36 | ## Package Speed 37 | 38 | If you wish to verify these results, you may run [the suite] yourself. You can 39 | find the latest results [here]. 40 | 41 | [the suite]: https://github.com/helperdiscord/http-benchmarks 42 | [here]: https://github.com/helperdiscord/http-benchmarks/blob/main/RESULTS.md 43 | 44 | Format key for package results: `N ops/sec ±MOE% (R)` where N is the number of 45 | operations per second achieved, MOE is the margin of error, and R is the number 46 | of times the test was ran. 47 | 48 | | CPU | Governor | Fastest | `got` | `request` | `node-fetch` | `centra` | `https` | `petitio (undici)` | `petitio (http)` | 49 | |:-------------:|:-----------:|:-----------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|:--------------------:|:-----------------------:|:-------------------:| 50 | | [i7-7700k][1] | Performance | `petitio (undici)` | 2,119 ±4.93% (70) | 5,786 ±6.52% (69) | 6,011 ±3.94% (70) | 9,245 ±4.46% (74) | 10,275 ±0.84% (83) | 16,349 ±2.44% (85) | N/A. | 51 | | [i7-6600U][2] | Performance | `petitio (undici)` | 1,913 ±0.54% (2073) | 4,738 ±0.59% (2068) | 4,393 ±0.56% (2072) | 5,800 ±0.92% (2068) | 5,912 ±0.55% (2071) | 13,088 ±0.54% (2074) | 7,301 ±0.53% (2073) | 52 | 53 | [1]: https://github.com/tbnritzdoge 54 | [2]: https://github.com/nytelife26 55 | -------------------------------------------------------------------------------- /docs/docs/pkg/classes/petitioresponse.petitioresponse-1.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse.petitioresponse-1" 3 | title: "Class: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Class: PetitioResponse 10 | 11 | [PetitioResponse](../modules/petitioresponse.md).PetitioResponse 12 | 13 | ## Constructors 14 | 15 | ### constructor 16 | 17 | \+ **new PetitioResponse**(): [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 18 | 19 | **Returns:** [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 20 | 21 | ## Properties 22 | 23 | ### body 24 | 25 | • **body**: *Buffer* 26 | 27 | The response body received from the server. 28 | This is updated through [PetitioResponse._addBody](petitioresponse.petitioresponse-1.md#_addbody), either 29 | from [PetitioRequest.send](petitiorequest.petitiorequest-1.md#send) or directly on a response object from 30 | another source. 31 | 32 | Defined in: [lib/PetitioResponse.ts:12](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioResponse.ts#L12) 33 | 34 | ___ 35 | 36 | ### headers 37 | 38 | • **headers**: *object* 39 | 40 | The response headers received from the server. 41 | This is updated through [PetitioResponse._parseHeaders](petitioresponse.petitioresponse-1.md#_parseheaders). 42 | 43 | #### Type declaration: 44 | 45 | Defined in: [lib/PetitioResponse.ts:17](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioResponse.ts#L17) 46 | 47 | ___ 48 | 49 | ### statusCode 50 | 51 | • **statusCode**: *null* \| *number*= null 52 | 53 | The status code received from the server. 54 | This is set only after the response is complete when headers are received 55 | or it can be set manually. 56 | 57 | Defined in: [lib/PetitioResponse.ts:23](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioResponse.ts#L23) 58 | 59 | ## Methods 60 | 61 | ### \_addBody 62 | 63 | ▸ **_addBody**(`chunks`: *Buffer*[] \| *Uint8Array*[]): *void* 64 | 65 | This takes the data chunks and creates a Buffer, and it sets 66 | that buffer as the body. 67 | 68 | #### Parameters: 69 | 70 | Name | Type | Description | 71 | :------ | :------ | :------ | 72 | `chunks` | *Buffer*[] \| *Uint8Array*[] | The body to set for the response. | 73 | 74 | **Returns:** *void* 75 | 76 | In place operation with no return. 77 | 78 | Defined in: [lib/PetitioResponse.ts:31](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioResponse.ts#L31) 79 | 80 | ___ 81 | 82 | ### \_parseHeaders 83 | 84 | ▸ **_parseHeaders**(`headers`: *string*[]): *void* 85 | 86 | #### Parameters: 87 | 88 | Name | Type | Description | 89 | :------ | :------ | :------ | 90 | `headers` | *string*[] | The headers to add. This is done by splitting the array into chunks of two, where the first value becomes the header and the latter becomes its value. This will also append values to the header as an array if it already exists. | 91 | 92 | **Returns:** *void* 93 | 94 | In place operation with no return. 95 | 96 | Defined in: [lib/PetitioResponse.ts:43](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioResponse.ts#L43) 97 | 98 | ___ 99 | 100 | ### json 101 | 102 | ▸ **json**(`encoding?`: BufferEncoding): T 103 | 104 | #### Type parameters: 105 | 106 | Name | Default | Description | 107 | :------ | :------ | :------ | 108 | `T` | *any* | Type casting parameter for the JSON result. | 109 | 110 | #### Parameters: 111 | 112 | Name | Type | Default value | 113 | :------ | :------ | :------ | 114 | `encoding` | BufferEncoding | "utf8" | 115 | 116 | **Returns:** T 117 | 118 | A serialized object result parsed from the response body. 119 | 120 | Defined in: [lib/PetitioResponse.ts:62](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioResponse.ts#L62) 121 | 122 | ___ 123 | 124 | ### text 125 | 126 | ▸ **text**(`encoding?`: BufferEncoding): *string* 127 | 128 | #### Parameters: 129 | 130 | Name | Type | Default value | 131 | :------ | :------ | :------ | 132 | `encoding` | BufferEncoding | "utf8" | 133 | 134 | **Returns:** *string* 135 | 136 | The response body decoded as as a string from the buffer, using either the encoding specified in `encoding` or UTF-8 by default.. 137 | 138 | Defined in: [lib/PetitioResponse.ts:70](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioResponse.ts#L70) 139 | -------------------------------------------------------------------------------- /docs/docs/pkg/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "petitio" 4 | slug: "/pkg" 5 | sidebar_label: "Readme" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | A zero-dependency HTTP library designed to be simple, fast, and type-strong. 13 | 14 | Credit to [Centra] for inspiration, as Petitio was originally a fork. 15 | 16 | [Centra]: https://github.com/ethanent/centra 17 | 18 | Useful links: 19 | - [Docs](https://helperdiscord.github.io/petitio) 20 | - [Usage examples](https://github.com/helperdiscord/petitio/tree/master/USAGE.md) 21 | - [Benchmarks / comparison](https://github.com/helperdiscord/petitio/tree/master/PERFORMANCE.md) 22 | 23 | ## What's with the name? 24 | 25 | *"Petitio"* is a hybrid between the French word for "small" ("petit"), and the 26 | Latin word for "request" ("petitio"). This library was originally called 27 | `@helperdiscord/centra`, but we changed it to evolve beyond our status as a 28 | Centra fork and set out to create the smallest and fastest high-level Node HTTP 29 | wrapper available. 30 | -------------------------------------------------------------------------------- /docs/docs/pkg/interfaces/petitiorequest.timeoutoptions.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest.timeoutoptions" 3 | title: "Interface: TimeoutOptions" 4 | sidebar_label: "TimeoutOptions" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Interface: TimeoutOptions 10 | 11 | [PetitioRequest](../modules/petitiorequest.md).TimeoutOptions 12 | 13 | **`see`** [Undici ClientOptions timeout documentation](https://github.com/nodejs/undici/blob/main/docs/api/Client.md#parameter-clientoptions) 14 | 15 | ## Properties 16 | 17 | ### bodyTimeout 18 | 19 | • `Optional` **bodyTimeout**: *number* 20 | 21 | Defined in: [lib/PetitioRequest.ts:25](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioRequest.ts#L25) 22 | 23 | ___ 24 | 25 | ### headersTimeout 26 | 27 | • `Optional` **headersTimeout**: *number* 28 | 29 | Defined in: [lib/PetitioRequest.ts:26](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioRequest.ts#L26) 30 | 31 | ___ 32 | 33 | ### keepAliveTimeout 34 | 35 | • `Optional` **keepAliveTimeout**: *number* 36 | 37 | Defined in: [lib/PetitioRequest.ts:27](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioRequest.ts#L27) 38 | -------------------------------------------------------------------------------- /docs/docs/pkg/modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "modules" 3 | title: "petitio" 4 | sidebar_label: "Table of contents" 5 | hide_table_of_contents: true 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | ## Table of contents 13 | 14 | ### Modules 15 | 16 | - [Petitio](modules/petitio.md) 17 | - [PetitioRequest](modules/petitiorequest.md) 18 | - [PetitioResponse](modules/petitioresponse.md) 19 | -------------------------------------------------------------------------------- /docs/docs/pkg/modules/petitio.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitio" 3 | title: "Module: Petitio" 4 | sidebar_label: "Petitio" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: Petitio 10 | 11 | ## Properties 12 | 13 | ### export= 14 | 15 | • **export=**: (`url`: *string* \| *URL*, `method`: [*HTTPMethod*](petitiorequest.md#httpmethod)) => [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | #### Type declaration: 18 | 19 | ▸ (`url`: *string* \| *URL*, `method?`: [*HTTPMethod*](petitiorequest.md#httpmethod)): [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 20 | 21 | **`see`** [PetitioRequest.constructor](../classes/petitiorequest.petitiorequest-1.md#constructor) 22 | 23 | #### Parameters: 24 | 25 | Name | Type | Default value | Description | 26 | :------ | :------ | :------ | :------ | 27 | `url` | *string* \| *URL* | - | The URL to start composing a request for. | 28 | `method` | [*HTTPMethod*](petitiorequest.md#httpmethod) | "GET" | - | 29 | 30 | **Returns:** [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 31 | 32 | The Petitio request instance for your URL. 33 | 34 | Defined in: [index.ts:5](https://github.com/helperdiscord/petitio/blob/23c8120/src/index.ts#L5) 35 | -------------------------------------------------------------------------------- /docs/docs/pkg/modules/petitiorequest.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest" 3 | title: "Module: PetitioRequest" 4 | sidebar_label: "PetitioRequest" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioRequest 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioRequest](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | ### Interfaces 18 | 19 | - [TimeoutOptions](../interfaces/petitiorequest.timeoutoptions.md) 20 | 21 | ## Type aliases 22 | 23 | ### HTTPMethod 24 | 25 | Ƭ **HTTPMethod**: *GET* \| *HEAD* \| *POST* \| *OPTIONS* \| *PUT* \| *DELETE* \| *TRACE* \| *CONNECT* \| *PATCH* 26 | 27 | Accepted HTTP methods (currently only supports up to HTTP/1.1). 28 | 29 | Defined in: [lib/PetitioRequest.ts:20](https://github.com/helperdiscord/petitio/blob/23c8120/src/lib/PetitioRequest.ts#L20) 30 | -------------------------------------------------------------------------------- /docs/docs/pkg/modules/petitioresponse.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse" 3 | title: "Module: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioResponse 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioResponse](../classes/petitioresponse.petitioresponse-1.md) 16 | -------------------------------------------------------------------------------- /docs/docusaurus.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable max-len */ 2 | /** @type {import('@docusaurus/types').DocusaurusConfig} */ 3 | module.exports = { 4 | title: "Petitio", 5 | tagline: "Zero-dependency HTTP library designed to be simple, fast, and type-strong.", 6 | url: "https://helperdiscord.github.io/petitio", 7 | baseUrl: "/petitio/", 8 | onBrokenLinks: "throw", 9 | onBrokenMarkdownLinks: "throw", 10 | i18n: { 11 | defaultLocale: "en-gb", 12 | locales: ["en-gb"] 13 | }, 14 | favicon: "img/favicon.ico", 15 | organizationName: "helperdiscord", 16 | projectName: "petitio", 17 | plugins: [ 18 | [ 19 | "docusaurus-plugin-typedoc", 20 | { 21 | entryPoints: [ 22 | "../src/index.ts", 23 | "../src/lib/PetitioRequest.ts", 24 | "../src/lib/PetitioResponse.ts" 25 | ], 26 | tsconfig: "../tsconfig.json", 27 | out: "pkg" 28 | } 29 | ] 30 | ], 31 | themeConfig: { 32 | hideableSidebar: true, 33 | colorMode: { 34 | respectPrefersColorScheme: true 35 | }, 36 | navbar: { 37 | hideOnScroll: true, 38 | title: "Petitio Docs", 39 | logo: { 40 | alt: "My Site Logo", 41 | src: "img/logo.svg" 42 | }, 43 | items: [ 44 | { 45 | to: "docs/", 46 | activeBasePath: "docs", 47 | label: "Docs", 48 | position: "left" 49 | }, 50 | { 51 | to: "blog", 52 | label: "Blog", 53 | position: "left" 54 | }, 55 | { 56 | to: "docs/metrics/performance", 57 | label: "Performance", 58 | position: "left" 59 | }, 60 | { 61 | type: "docsVersionDropdown", 62 | position: "right", 63 | dropdownItemsBefore: [], 64 | dropdownItemsAfter: [{to: "/versions", label: "All versions"}], 65 | dropdownActiveClassDisabled: true, 66 | docsPluginId: "default" 67 | }, 68 | { 69 | type: "localeDropdown", 70 | position: "right", 71 | dropdownItemsBefore: [], 72 | dropdownItemsAfter: [{to: "https://github.com/helperdiscord/petitio/issues/14", label: "Help us translate!"}] 73 | }, 74 | { 75 | href: "https://github.com/helperdiscord/petitio", 76 | label: "GitHub", 77 | position: "right" 78 | } 79 | ] 80 | }, 81 | footer: { 82 | style: "dark", 83 | links: [ 84 | { 85 | title: "Docs", 86 | items: [ 87 | { 88 | label: "Getting Started", 89 | to: "docs/guides/getting-started" 90 | }, 91 | { 92 | label: "API Reference", 93 | to: "docs/pkg/index" 94 | } 95 | ] 96 | }, 97 | { 98 | title: "More", 99 | items: [ 100 | { 101 | label: "Blog", 102 | to: "blog" 103 | }, 104 | { 105 | label: "GitHub", 106 | href: "https://github.com/helperdiscord/petitio" 107 | } 108 | ] 109 | } 110 | ], 111 | copyright: `Copyright © ${new Date().getFullYear()} helperdiscord. Built with Docusaurus and TypeDoc.` 112 | } 113 | }, 114 | presets: [ 115 | [ 116 | "@docusaurus/preset-classic", 117 | { 118 | docs: { 119 | sidebarPath: require.resolve("./sidebars.js"), 120 | editUrl: "https://github.com/helperdiscord/petitio/edit/master/docs/", 121 | editCurrentVersion: false, 122 | editLocalizedFiles: true, 123 | showLastUpdateTime: true 124 | }, 125 | blog: { 126 | showReadingTime: true, 127 | editUrl: "https://github.com/helperdiscord/petitio/edit/master/docs/", 128 | editLocalizedFiles: true 129 | }, 130 | theme: { 131 | customCss: require.resolve("./src/css/custom.css") 132 | } 133 | } 134 | ] 135 | ] 136 | }; 137 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/code.json: -------------------------------------------------------------------------------- 1 | { 2 | "version.docs": { 3 | "message": "Documentation", 4 | "description": "Version documentation header" 5 | }, 6 | "version.notes": { 7 | "message": "Release Notes", 8 | "description": "Version release notes header" 9 | }, 10 | "features.speed.title": { 11 | "message": "Warp Speed, Mr. Sulu", 12 | "description": "Clever reference that hints to us being fast" 13 | }, 14 | "features.speed.description": { 15 | "message": "Petitio is the fastest mainstream high-level HTTP library\n\t\t\tavailable on NPM. Check {performance} for more details.", 16 | "description": "Details about us being the fastest and benchmarks" 17 | }, 18 | "homepage.tagline": { 19 | "message": "Zero-dependency HTTP library designed to be simple, fast, and type-strong." 20 | }, 21 | "homepage.docsLink": { 22 | "message": "Get Started" 23 | }, 24 | "versions.latest.title": { 25 | "message": "Latest" 26 | }, 27 | "versions.latest.description": { 28 | "message": "Here you can find the documentation for the latest released version." 29 | }, 30 | "versions.next.title": { 31 | "message": "Next (Unreleased)" 32 | }, 33 | "versions.next.description": { 34 | "message": "Here you can find the documentation for the unreleased bleeding-edge version." 35 | }, 36 | "versions.past.title": { 37 | "message": "Previous versions (unmaintained)" 38 | }, 39 | "versions.past.description": { 40 | "message": "Here you can find the documentation for archived versions." 41 | }, 42 | "versions.pageTitle": { 43 | "message": "Petitio documentation versions" 44 | }, 45 | "theme.NotFound.title": { 46 | "message": "Page Not Found", 47 | "description": "The title of the 404 page" 48 | }, 49 | "theme.NotFound.p1": { 50 | "message": "We could not find what you were looking for.", 51 | "description": "The first paragraph of the 404 page" 52 | }, 53 | "theme.NotFound.p2": { 54 | "message": "Please contact the owner of the site that linked you to the original URL and let them know their link is broken.", 55 | "description": "The 2nd paragraph of the 404 page" 56 | }, 57 | "theme.AnnouncementBar.closeButtonAriaLabel": { 58 | "message": "Close", 59 | "description": "The ARIA label for close button of announcement bar" 60 | }, 61 | "theme.blog.paginator.navAriaLabel": { 62 | "message": "Blog list page navigation", 63 | "description": "The ARIA label for the blog pagination" 64 | }, 65 | "theme.blog.paginator.newerEntries": { 66 | "message": "Newer Entries", 67 | "description": "The label used to navigate to the newer blog posts page (previous page)" 68 | }, 69 | "theme.blog.paginator.olderEntries": { 70 | "message": "Older Entries", 71 | "description": "The label used to navigate to the older blog posts page (next page)" 72 | }, 73 | "theme.blog.post.readingTime.plurals": { 74 | "message": "One min read|{readingTime} min read", 75 | "description": "Pluralized label for \"{readingTime} min read\". Use as much plural forms (separated by \"|\") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)" 76 | }, 77 | "theme.tags.tagsListLabel": { 78 | "message": "Tags:", 79 | "description": "The label alongside a tag list" 80 | }, 81 | "theme.blog.post.readMore": { 82 | "message": "Read More", 83 | "description": "The label used in blog post item excerpts to link to full blog posts" 84 | }, 85 | "theme.blog.post.paginator.navAriaLabel": { 86 | "message": "Blog post page navigation", 87 | "description": "The ARIA label for the blog posts pagination" 88 | }, 89 | "theme.blog.post.paginator.newerPost": { 90 | "message": "Newer Post", 91 | "description": "The blog post button label to navigate to the newer/previous post" 92 | }, 93 | "theme.blog.post.paginator.olderPost": { 94 | "message": "Older Post", 95 | "description": "The blog post button label to navigate to the older/next post" 96 | }, 97 | "theme.tags.tagsPageTitle": { 98 | "message": "Tags", 99 | "description": "The title of the tag list page" 100 | }, 101 | "theme.blog.post.plurals": { 102 | "message": "One post|{count} posts", 103 | "description": "Pluralized label for \"{count} posts\". Use as much plural forms (separated by \"|\") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)" 104 | }, 105 | "theme.blog.tagTitle": { 106 | "message": "{nPosts} tagged with \"{tagName}\"", 107 | "description": "The title of the page for a blog tag" 108 | }, 109 | "theme.tags.tagsPageLink": { 110 | "message": "View All Tags", 111 | "description": "The label of the link targeting the tag list page" 112 | }, 113 | "theme.CodeBlock.copyButtonAriaLabel": { 114 | "message": "Copy code to clipboard", 115 | "description": "The ARIA label for copy code blocks button" 116 | }, 117 | "theme.CodeBlock.copied": { 118 | "message": "Copied", 119 | "description": "The copied button label on code blocks" 120 | }, 121 | "theme.CodeBlock.copy": { 122 | "message": "Copy", 123 | "description": "The copy button label on code blocks" 124 | }, 125 | "theme.docs.sidebar.expandButtonTitle": { 126 | "message": "Expand sidebar", 127 | "description": "The ARIA label and title attribute for expand button of doc sidebar" 128 | }, 129 | "theme.docs.sidebar.expandButtonAriaLabel": { 130 | "message": "Expand sidebar", 131 | "description": "The ARIA label and title attribute for expand button of doc sidebar" 132 | }, 133 | "theme.docs.paginator.navAriaLabel": { 134 | "message": "Docs pages navigation", 135 | "description": "The ARIA label for the docs pagination" 136 | }, 137 | "theme.docs.paginator.previous": { 138 | "message": "Previous", 139 | "description": "The label used to navigate to the previous doc" 140 | }, 141 | "theme.docs.paginator.next": { 142 | "message": "Next", 143 | "description": "The label used to navigate to the next doc" 144 | }, 145 | "theme.docs.sidebar.responsiveCloseButtonLabel": { 146 | "message": "Close menu", 147 | "description": "The ARIA label for close button of mobile doc sidebar" 148 | }, 149 | "theme.docs.sidebar.responsiveOpenButtonLabel": { 150 | "message": "Open menu", 151 | "description": "The ARIA label for open button of mobile doc sidebar" 152 | }, 153 | "theme.docs.sidebar.collapseButtonTitle": { 154 | "message": "Collapse sidebar", 155 | "description": "The title attribute for collapse button of doc sidebar" 156 | }, 157 | "theme.docs.sidebar.collapseButtonAriaLabel": { 158 | "message": "Collapse sidebar", 159 | "description": "The title attribute for collapse button of doc sidebar" 160 | }, 161 | "theme.docs.versions.unreleasedVersionLabel": { 162 | "message": "This is unreleased documentation for {siteTitle} {versionLabel} version.", 163 | "description": "The label used to tell the user that he's browsing an unreleased doc version" 164 | }, 165 | "theme.docs.versions.unmaintainedVersionLabel": { 166 | "message": "This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.", 167 | "description": "The label used to tell the user that he's browsing an unmaintained doc version" 168 | }, 169 | "theme.docs.versions.latestVersionSuggestionLabel": { 170 | "message": "For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).", 171 | "description": "The label userd to tell the user that he's browsing an unmaintained doc version" 172 | }, 173 | "theme.docs.versions.latestVersionLinkLabel": { 174 | "message": "latest version", 175 | "description": "The label used for the latest version suggestion link label" 176 | }, 177 | "theme.common.editThisPage": { 178 | "message": "Edit this page", 179 | "description": "The link label to edit the current page" 180 | }, 181 | "theme.common.headingLinkTitle": { 182 | "message": "Direct link to heading", 183 | "description": "Title for link to heading" 184 | }, 185 | "theme.lastUpdated.atDate": { 186 | "message": " on {date}", 187 | "description": "The words used to describe on which date a page has been last updated" 188 | }, 189 | "theme.lastUpdated.byUser": { 190 | "message": " by {user}", 191 | "description": "The words used to describe by who the page has been last updated" 192 | }, 193 | "theme.lastUpdated.lastUpdatedAtBy": { 194 | "message": "Last updated{atDate}{byUser}", 195 | "description": "The sentence used to display when a page has been last updated, and by who" 196 | }, 197 | "theme.common.skipToMainContent": { 198 | "message": "Skip to main content", 199 | "description": "The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation" 200 | } 201 | } -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current.json: -------------------------------------------------------------------------------- 1 | { 2 | "version.label": { 3 | "message": "Next", 4 | "description": "The label for version current" 5 | }, 6 | "sidebar.docs.category.Guides": { 7 | "message": "Guides", 8 | "description": "The label for category Guides in sidebar docs" 9 | }, 10 | "sidebar.docs.category.Metrics": { 11 | "message": "Metrics", 12 | "description": "The label for category Metrics in sidebar docs" 13 | }, 14 | "sidebar.docs.category.API Reference": { 15 | "message": "API Reference", 16 | "description": "The label for category API Reference in sidebar docs" 17 | }, 18 | "sidebar.docs.category.Modules": { 19 | "message": "Modules", 20 | "description": "The label for category Modules in sidebar docs" 21 | }, 22 | "sidebar.docs.category.Classes": { 23 | "message": "Classes", 24 | "description": "The label for category Classes in sidebar docs" 25 | }, 26 | "sidebar.docs.category.Interfaces": { 27 | "message": "Interfaces", 28 | "description": "The label for category Interfaces in sidebar docs" 29 | } 30 | } -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/axios.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 388 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 388 kB 17 | 388 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/got.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.33 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.33 MB 17 | 1.33 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/isomorphic-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 216 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 216 kB 17 | 216 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/node-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 155 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 155 kB 17 | 155 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/petitio.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 41.2 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 41.2 kB 17 | 41.2 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/phin.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 23.0 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 23.0 kB 17 | 23.0 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/r2.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 201 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 201 kB 17 | 201 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/request.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 3.84 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 3.84 MB 17 | 3.84 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/assets/superagent.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.70 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.70 MB 17 | 1.70 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/guides/getting-started.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "getting-started" 3 | title: "Getting Started" 4 | --- 5 | 6 | **Note: Petitio supports both `require` and `import` syntax out of the box, so 7 | there's no need to do any pesky ESM or CJS hacks.** 8 | 9 | ## Basic Usage 10 | 11 | The [default export] of Petitio is a wrapper function for [PetitioRequest], 12 | meaning all you need to get started is as follows: 13 | 14 | ```typescript 15 | import petitio from "petitio"; 16 | 17 | const request = petitio("https://example.com"); 18 | ``` 19 | 20 | That instantiates a [PetitioRequest] for `example.com`. Simple right? 21 | Let's take a look at how we send requests and work with responses. 22 | 23 | ```typescript 24 | const result = await request.send().text(); 25 | // equivalent to 26 | const result = await request.text(); 27 | ``` 28 | 29 | Fast and clean. Beautiful, even. But how does that work? 30 | [PetitioRequest#send][send] instructs Petitio to send the current 31 | [PetitioRequest] and returns a [PetitioResponse] with the response data, and 32 | then [PetitioResponse#text][response-text] parses the response body from 33 | a buffer to a string. The shorthand form of this is 34 | [PetitioRequest#text][request-text], which sends the request and invokes text 35 | parsing for you in one call. 36 | 37 | That's the basics covered! Check out some more [usage examples], or read 38 | through our [other guides]. 39 | 40 | [default export]: ../pkg/modules/petitio#export 41 | [PetitioRequest]: ../pkg/classes/petitiorequest.petitiorequest-1 42 | [PetitioResponse]: ../pkg/classes/petitioresponse.petitioresponse-1 43 | [send]: ../pkg/classes/petitiorequest.petitiorequest-1#send 44 | [response-text]: ../pkg/classes/petitioresponse.petitioresponse-1#text 45 | [request-text]: ../pkg/classes/petitiorequest.petitiorequest-1#text 46 | [usage examples]: https://github.com/helperdiscord/petitio/tree/master/USAGE.md 47 | [other guides]: ../ 48 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "index" 4 | slug: "/" 5 | sidebar_label: "Home" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # Petitio Reference 11 | 12 | Here you will find the documentation for Petitio. 13 | 14 | We suggest you start by checking out the following: 15 | - [The "Getting Started" guide](/docs/guides/getting-started) 16 | - [The API Reference](/docs/pkg) 17 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/metrics/performance.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "performance" 3 | title: "Performance" 4 | --- 5 | 6 | ## Preface 7 | 8 | These results are collected from [a suite] managed by helperdiscord and verified 9 | by Kludge Cyber Systems. Anyone may add to them with the results from their own 10 | system, and they are kept up to date with at least two samples from each 11 | version. 12 | 13 | [a suite]: https://github.com/helperdiscord/http-benchmarks 14 | 15 | ## Package Size 16 | 17 | Here you can see how efficient Petitio is in contrast to its competitors in 18 | terms of bundle size. 19 | 20 | 21 | Results table 22 | 23 | | Package | Size | 24 | |------------------|--------------------------------------------------------------------------------------------------------------------------------| 25 | | request | [](https://packagephobia.now.sh/result?p=request@2.88.2) | 26 | | superagent | [](https://packagephobia.now.sh/result?p=superagent@6.1.0) | 27 | | got | [](https://packagephobia.now.sh/result?p=got@11.8.2) | 28 | | axios | [](https://packagephobia.now.sh/result?p=axios@0.21.1) | 29 | | isomorphic-fetch | [](https://packagephobia.now.sh/result?p=isomorphic-fetch@3.0) | 30 | | r2 | [](https://packagephobia.now.sh/result?p=r2@2.0.1) | 31 | | node-fetch | [](https://packagephobia.now.sh/result?p=node-fetch@2.6.1) | 32 | | petitio | [](https://packagephobia.now.sh/result?p=petitio@1.1.0) | 33 | | phin | [](https://packagephobia.now.sh/result?p=phin@3.5.1) | 34 | 35 | 36 | ## Package Speed 37 | 38 | If you wish to verify these results, you may run [the suite] yourself. You can 39 | find the latest results [here]. 40 | 41 | [the suite]: https://github.com/helperdiscord/http-benchmarks 42 | [here]: https://github.com/helperdiscord/http-benchmarks/blob/main/RESULTS.md 43 | 44 | Format key for package results: `N ops/sec ±MOE% (R)` where N is the number of 45 | operations per second achieved, MOE is the margin of error, and R is the number 46 | of times the test was ran. 47 | 48 | | CPU | Governor | Fastest | `got` | `request` | `node-fetch` | `centra` | `https` | `petitio (undici)` | `petitio (http)` | 49 | |:-------------:|:-----------:|:-----------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|:--------------------:|:-----------------------:|:-------------------:| 50 | | [i7-7700k][1] | Performance | `petitio (undici)` | 2,119 ±4.93% (70) | 5,786 ±6.52% (69) | 6,011 ±3.94% (70) | 9,245 ±4.46% (74) | 10,275 ±0.84% (83) | 16,349 ±2.44% (85) | N/A. | 51 | | [i7-6600U][2] | Performance | `petitio (undici)` | 1,913 ±0.54% (2073) | 4,738 ±0.59% (2068) | 4,393 ±0.56% (2072) | 5,800 ±0.92% (2068) | 5,912 ±0.55% (2071) | 13,088 ±0.54% (2074) | 7,301 ±0.53% (2073) | 52 | 53 | [1]: https://github.com/tbnritzdoge 54 | [2]: https://github.com/nytelife26 55 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/pkg/classes/petitioresponse.petitioresponse-1.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse.petitioresponse-1" 3 | title: "Class: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Class: PetitioResponse 10 | 11 | [PetitioResponse](../modules/petitioresponse.md).PetitioResponse 12 | 13 | ## Constructors 14 | 15 | ### constructor 16 | 17 | \+ **new PetitioResponse**(): [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 18 | 19 | **Returns:** [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 20 | 21 | ## Properties 22 | 23 | ### body 24 | 25 | • **body**: *Buffer* 26 | 27 | The response body received from the server. 28 | This is updated in chunks through [PetitioResponse._addChunk](petitioresponse.petitioresponse-1.md#_addchunk), either 29 | from [PetitioRequest.send](petitiorequest.petitiorequest-1.md#send) or directly on a response object from 30 | another source. 31 | 32 | Defined in: [lib/PetitioResponse.ts:12](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioResponse.ts#L12) 33 | 34 | ___ 35 | 36 | ### headers 37 | 38 | • **headers**: *object* 39 | 40 | The response headers received from the server. 41 | This is updated through [PetitioResponse._parseHeaders](petitioresponse.petitioresponse-1.md#_parseheaders). 42 | 43 | #### Type declaration: 44 | 45 | Defined in: [lib/PetitioResponse.ts:17](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioResponse.ts#L17) 46 | 47 | ___ 48 | 49 | ### statusCode 50 | 51 | • **statusCode**: *null* \| *number*= null 52 | 53 | The status code received from the server. 54 | This is set only after the response is complete when headers are received 55 | or it can be set manually. 56 | 57 | Defined in: [lib/PetitioResponse.ts:23](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioResponse.ts#L23) 58 | 59 | ## Methods 60 | 61 | ### \_addChunk 62 | 63 | ▸ **_addChunk**(`chunk`: *Buffer* \| *Uint8Array*): *void* 64 | 65 | This appends data to the body, dynamically reallocating the buffer size 66 | as chunks are added. Therefore, this is currently unsuitable for handling 67 | large responses, as the exact size is allocated in memory as a buffer. 68 | 69 | #### Parameters: 70 | 71 | Name | Type | Description | 72 | :------ | :------ | :------ | 73 | `chunk` | *Buffer* \| *Uint8Array* | The chunk of data to append to the body. | 74 | 75 | **Returns:** *void* 76 | 77 | In place operation with no return. 78 | 79 | Defined in: [lib/PetitioResponse.ts:32](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioResponse.ts#L32) 80 | 81 | ___ 82 | 83 | ### \_parseHeaders 84 | 85 | ▸ **_parseHeaders**(`headers`: *string*[]): *void* 86 | 87 | #### Parameters: 88 | 89 | Name | Type | Description | 90 | :------ | :------ | :------ | 91 | `headers` | *string*[] | The headers to add. This is done by splitting the array into chunks of two, where the first value becomes the header and the latter becomes its value. This will also append values to the header as an array if it already exists. | 92 | 93 | **Returns:** *void* 94 | 95 | In place operation with no return. 96 | 97 | Defined in: [lib/PetitioResponse.ts:43](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioResponse.ts#L43) 98 | 99 | ___ 100 | 101 | ### json 102 | 103 | ▸ **json**(): T 104 | 105 | #### Type parameters: 106 | 107 | Name | Default | Description | 108 | :------ | :------ | :------ | 109 | `T` | *any* | Type casting parameter for the JSON result. | 110 | 111 | **Returns:** T 112 | 113 | A serialized object result parsed from the response body. 114 | 115 | Defined in: [lib/PetitioResponse.ts:61](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioResponse.ts#L61) 116 | 117 | ___ 118 | 119 | ### text 120 | 121 | ▸ **text**(): *string* 122 | 123 | **Returns:** *string* 124 | 125 | The response body decoded as a UTF-8 string from the buffer. 126 | 127 | Defined in: [lib/PetitioResponse.ts:68](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioResponse.ts#L68) 128 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/pkg/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "petitio" 4 | slug: "/pkg" 5 | sidebar_label: "Readme" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | A zero-dependency HTTP library designed to be simple, fast, and type-strong. 13 | 14 | Credit to [Centra] for inspiration, as Petitio was originally a fork. 15 | 16 | [Centra]: https://github.com/ethanent/centra 17 | 18 | Useful links: 19 | - [Docs](https://helperdiscord.github.io/petitio) 20 | - [Usage examples](https://github.com/helperdiscord/petitio/tree/master/USAGE.md) 21 | - [Benchmarks / comparison](https://github.com/helperdiscord/petitio/tree/master/PERFORMANCE.md) 22 | 23 | ## What's with the name? 24 | 25 | *"Petitio"* is a hybrid between the French word for "small" ("petit"), and the 26 | Latin word for "request" ("petitio"). This library was originally called 27 | `@helperdiscord/centra`, but we changed it to evolve beyond our status as a 28 | Centra fork and set out to create the smallest and fastest high-level Node HTTP 29 | wrapper available. 30 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/pkg/interfaces/petitiorequest.timeoutoptions.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest.timeoutoptions" 3 | title: "Interface: TimeoutOptions" 4 | sidebar_label: "TimeoutOptions" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Interface: TimeoutOptions 10 | 11 | [PetitioRequest](../modules/petitiorequest.md).TimeoutOptions 12 | 13 | **`see`** [Undici ClientOptions timeout documentation](https://github.com/nodejs/undici/blob/main/docs/api/Client.md#parameter-clientoptions) 14 | 15 | ## Properties 16 | 17 | ### bodyTimeout 18 | 19 | • `Optional` **bodyTimeout**: *number* 20 | 21 | Defined in: [lib/PetitioRequest.ts:24](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioRequest.ts#L24) 22 | 23 | ___ 24 | 25 | ### headersTimeout 26 | 27 | • `Optional` **headersTimeout**: *number* 28 | 29 | Defined in: [lib/PetitioRequest.ts:25](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioRequest.ts#L25) 30 | 31 | ___ 32 | 33 | ### keepAliveTimeout 34 | 35 | • `Optional` **keepAliveTimeout**: *number* 36 | 37 | Defined in: [lib/PetitioRequest.ts:26](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioRequest.ts#L26) 38 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/pkg/modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "modules" 3 | title: "petitio" 4 | sidebar_label: "Table of contents" 5 | hide_table_of_contents: true 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | ## Table of contents 13 | 14 | ### Modules 15 | 16 | - [Petitio](modules/petitio.md) 17 | - [PetitioRequest](modules/petitiorequest.md) 18 | - [PetitioResponse](modules/petitioresponse.md) 19 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/pkg/modules/petitio.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitio" 3 | title: "Module: Petitio" 4 | sidebar_label: "Petitio" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: Petitio 10 | 11 | ## Properties 12 | 13 | ### export= 14 | 15 | • **export=**: (`url`: *string* \| *URL*, `method`: [*HTTPMethod*](petitiorequest.md#httpmethod)) => [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | #### Type declaration: 18 | 19 | ▸ (`url`: *string* \| *URL*, `method?`: [*HTTPMethod*](petitiorequest.md#httpmethod)): [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 20 | 21 | **`see`** [PetitioRequest.constructor](../classes/petitiorequest.petitiorequest-1.md#constructor) 22 | 23 | #### Parameters: 24 | 25 | Name | Type | Default value | Description | 26 | :------ | :------ | :------ | :------ | 27 | `url` | *string* \| *URL* | - | The URL to start composing a request for. | 28 | `method` | [*HTTPMethod*](petitiorequest.md#httpmethod) | "GET" | - | 29 | 30 | **Returns:** [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 31 | 32 | The Petitio request instance for your URL. 33 | 34 | Defined in: [index.ts:5](https://github.com/helperdiscord/petitio/blob/eff2aca/src/index.ts#L5) 35 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/pkg/modules/petitiorequest.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest" 3 | title: "Module: PetitioRequest" 4 | sidebar_label: "PetitioRequest" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioRequest 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioRequest](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | ### Interfaces 18 | 19 | - [TimeoutOptions](../interfaces/petitiorequest.timeoutoptions.md) 20 | 21 | ## Type aliases 22 | 23 | ### HTTPMethod 24 | 25 | Ƭ **HTTPMethod**: *GET* \| *POST* \| *PATCH* \| *DELETE* \| *PUT* 26 | 27 | Accepted HTTP methods (currently only supports up to HTTP/1.1). 28 | 29 | Defined in: [lib/PetitioRequest.ts:19](https://github.com/helperdiscord/petitio/blob/eff2aca/src/lib/PetitioRequest.ts#L19) 30 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/current/pkg/modules/petitioresponse.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse" 3 | title: "Module: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioResponse 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioResponse](../classes/petitioresponse.petitioresponse-1.md) 16 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "version.label": { 3 | "message": "1.2.0", 4 | "description": "The label for version 1.2.0" 5 | }, 6 | "sidebar.docs.category.Guides": { 7 | "message": "Guides", 8 | "description": "The label for category Guides in sidebar docs" 9 | }, 10 | "sidebar.docs.category.Metrics": { 11 | "message": "Metrics", 12 | "description": "The label for category Metrics in sidebar docs" 13 | }, 14 | "sidebar.docs.category.API Reference": { 15 | "message": "API Reference", 16 | "description": "The label for category API Reference in sidebar docs" 17 | }, 18 | "sidebar.docs.category.Modules": { 19 | "message": "Modules", 20 | "description": "The label for category Modules in sidebar docs" 21 | }, 22 | "sidebar.docs.category.Classes": { 23 | "message": "Classes", 24 | "description": "The label for category Classes in sidebar docs" 25 | }, 26 | "sidebar.docs.category.Interfaces": { 27 | "message": "Interfaces", 28 | "description": "The label for category Interfaces in sidebar docs" 29 | } 30 | } -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/axios.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 388 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 388 kB 17 | 388 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/got.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.33 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.33 MB 17 | 1.33 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/isomorphic-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 216 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 216 kB 17 | 216 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/node-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 155 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 155 kB 17 | 155 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/petitio.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 41.2 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 41.2 kB 17 | 41.2 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/phin.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 23.0 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 23.0 kB 17 | 23.0 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/r2.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 201 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 201 kB 17 | 201 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/request.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 3.84 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 3.84 MB 17 | 3.84 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/assets/superagent.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.70 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.70 MB 17 | 1.70 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/guides/getting-started.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "getting-started" 3 | title: "Getting Started" 4 | --- 5 | 6 | **Note: Petitio supports both `require` and `import` syntax out of the box, so 7 | there's no need to do any pesky ESM or CJS hacks.** 8 | 9 | ## Basic Usage 10 | 11 | The [default export] of Petitio is a wrapper function for [PetitioRequest], 12 | meaning all you need to get started is as follows: 13 | 14 | ```typescript 15 | import petitio from "petitio"; 16 | 17 | const request = petitio("https://example.com"); 18 | ``` 19 | 20 | That instantiates a [PetitioRequest] for `example.com`. Simple right? 21 | Let's take a look at how we send requests and work with responses. 22 | 23 | ```typescript 24 | const result = await request.send().text(); 25 | // equivalent to 26 | const result = await request.text(); 27 | ``` 28 | 29 | Fast and clean. Beautiful, even. But how does that work? 30 | [PetitioRequest#send][send] instructs Petitio to send the current 31 | [PetitioRequest] and returns a [PetitioResponse] with the response data, and 32 | then [PetitioResponse#text][response-text] parses the response body from 33 | a buffer to a string. The shorthand form of this is 34 | [PetitioRequest#text][request-text], which sends the request and invokes text 35 | parsing for you in one call. 36 | 37 | That's the basics covered! Check out some more [usage examples], or read 38 | through our [other guides]. 39 | 40 | [default export]: ../pkg/modules/petitio#export 41 | [PetitioRequest]: ../pkg/classes/petitiorequest.petitiorequest-1 42 | [PetitioResponse]: ../pkg/classes/petitioresponse.petitioresponse-1 43 | [send]: ../pkg/classes/petitiorequest.petitiorequest-1#send 44 | [response-text]: ../pkg/classes/petitioresponse.petitioresponse-1#text 45 | [request-text]: ../pkg/classes/petitiorequest.petitiorequest-1#text 46 | [usage examples]: https://github.com/helperdiscord/petitio/tree/master/USAGE.md 47 | [other guides]: ../ 48 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "index" 4 | slug: "/" 5 | sidebar_label: "Home" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # Petitio Reference 11 | 12 | Here you will find the documentation for Petitio. 13 | 14 | We suggest you start by checking out the following: 15 | - [The "Getting Started" guide](/docs/guides/getting-started) 16 | - [The API Reference](/docs/pkg) 17 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/metrics/performance.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "performance" 3 | title: "Performance" 4 | --- 5 | 6 | ## Preface 7 | 8 | These results are collected from [a suite] managed by helperdiscord and verified 9 | by Kludge Cyber Systems. Anyone may add to them with the results from their own 10 | system, and they are kept up to date with at least two samples from each 11 | version. 12 | 13 | [a suite]: https://github.com/helperdiscord/http-benchmarks 14 | 15 | ## Package Size 16 | 17 | Here you can see how efficient Petitio is in contrast to its competitors in 18 | terms of bundle size. 19 | 20 | 21 | Results table 22 | 23 | | Package | Size | 24 | |------------------|--------------------------------------------------------------------------------------------------------------------------------| 25 | | request | [](https://packagephobia.now.sh/result?p=request@2.88.2) | 26 | | superagent | [](https://packagephobia.now.sh/result?p=superagent@6.1.0) | 27 | | got | [](https://packagephobia.now.sh/result?p=got@11.8.2) | 28 | | axios | [](https://packagephobia.now.sh/result?p=axios@0.21.1) | 29 | | isomorphic-fetch | [](https://packagephobia.now.sh/result?p=isomorphic-fetch@3.0) | 30 | | r2 | [](https://packagephobia.now.sh/result?p=r2@2.0.1) | 31 | | node-fetch | [](https://packagephobia.now.sh/result?p=node-fetch@2.6.1) | 32 | | petitio | [](https://packagephobia.now.sh/result?p=petitio@1.1.0) | 33 | | phin | [](https://packagephobia.now.sh/result?p=phin@3.5.1) | 34 | 35 | 36 | ## Package Speed 37 | 38 | If you wish to verify these results, you may run [the suite] yourself. You can 39 | find the latest results [here]. 40 | 41 | [the suite]: https://github.com/helperdiscord/http-benchmarks 42 | [here]: https://github.com/helperdiscord/http-benchmarks/blob/main/RESULTS.md 43 | 44 | Format key for package results: `N ops/sec ±MOE% (R)` where N is the number of 45 | operations per second achieved, MOE is the margin of error, and R is the number 46 | of times the test was ran. 47 | 48 | | CPU | Governor | Fastest | `got` | `request` | `node-fetch` | `centra` | `https` | `petitio (undici)` | `petitio (http)` | 49 | |:-------------:|:-----------:|:-----------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|:--------------------:|:-----------------------:|:-------------------:| 50 | | [i7-7700k][1] | Performance | `petitio (undici)` | 2,119 ±4.93% (70) | 5,786 ±6.52% (69) | 6,011 ±3.94% (70) | 9,245 ±4.46% (74) | 10,275 ±0.84% (83) | 16,349 ±2.44% (85) | N/A. | 51 | | [i7-6600U][2] | Performance | `petitio (undici)` | 1,913 ±0.54% (2073) | 4,738 ±0.59% (2068) | 4,393 ±0.56% (2072) | 5,800 ±0.92% (2068) | 5,912 ±0.55% (2071) | 13,088 ±0.54% (2074) | 7,301 ±0.53% (2073) | 52 | 53 | [1]: https://github.com/tbnritzdoge 54 | [2]: https://github.com/nytelife26 55 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/pkg/classes/petitioresponse.petitioresponse-1.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse.petitioresponse-1" 3 | title: "Class: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Class: PetitioResponse 10 | 11 | [PetitioResponse](../modules/petitioresponse.md).PetitioResponse 12 | 13 | ## Constructors 14 | 15 | ### constructor 16 | 17 | \+ **new PetitioResponse**(): [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 18 | 19 | **Returns:** [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 20 | 21 | ## Properties 22 | 23 | ### body 24 | 25 | • **body**: *Buffer* 26 | 27 | The response body received from the server. 28 | This is updated in chunks through [PetitioResponse._addChunk](petitioresponse.petitioresponse-1.md#_addchunk), either 29 | from [PetitioRequest.send](petitiorequest.petitiorequest-1.md#send) or directly on a response object from 30 | another source. 31 | 32 | Defined in: [lib/PetitioResponse.ts:12](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L12) 33 | 34 | ___ 35 | 36 | ### headers 37 | 38 | • **headers**: *object* 39 | 40 | The response headers received from the server. 41 | This is updated through [PetitioResponse._parseHeaders](petitioresponse.petitioresponse-1.md#_parseheaders). 42 | 43 | #### Type declaration: 44 | 45 | Defined in: [lib/PetitioResponse.ts:17](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L17) 46 | 47 | ___ 48 | 49 | ### statusCode 50 | 51 | • **statusCode**: *null* \| *number*= null 52 | 53 | The status code received from the server. 54 | This is set only after the response is complete when headers are received 55 | or it can be set manually. 56 | 57 | Defined in: [lib/PetitioResponse.ts:23](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L23) 58 | 59 | ## Methods 60 | 61 | ### \_addChunk 62 | 63 | ▸ **_addChunk**(`chunk`: *Buffer* \| *Uint8Array*): *void* 64 | 65 | This appends data to the body, dynamically reallocating the buffer size 66 | as chunks are added. Therefore, this is currently unsuitable for handling 67 | large responses, as the exact size is allocated in memory as a buffer. 68 | 69 | #### Parameters: 70 | 71 | Name | Type | Description | 72 | :------ | :------ | :------ | 73 | `chunk` | *Buffer* \| *Uint8Array* | The chunk of data to append to the body. | 74 | 75 | **Returns:** *void* 76 | 77 | In place operation with no return. 78 | 79 | Defined in: [lib/PetitioResponse.ts:32](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L32) 80 | 81 | ___ 82 | 83 | ### \_parseHeaders 84 | 85 | ▸ **_parseHeaders**(`headers`: *string*[]): *void* 86 | 87 | #### Parameters: 88 | 89 | Name | Type | Description | 90 | :------ | :------ | :------ | 91 | `headers` | *string*[] | The headers to add. This is done by splitting the array into chunks of two, where the first value becomes the header and the latter becomes its value. This will also append values to the header as an array if it already exists. | 92 | 93 | **Returns:** *void* 94 | 95 | In place operation with no return. 96 | 97 | Defined in: [lib/PetitioResponse.ts:43](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L43) 98 | 99 | ___ 100 | 101 | ### json 102 | 103 | ▸ **json**(`encoding?`: BufferEncoding): T 104 | 105 | #### Type parameters: 106 | 107 | Name | Default | Description | 108 | :------ | :------ | :------ | 109 | `T` | *any* | Type casting parameter for the JSON result. | 110 | 111 | #### Parameters: 112 | 113 | Name | Type | Default value | 114 | :------ | :------ | :------ | 115 | `encoding` | BufferEncoding | "utf8" | 116 | 117 | **Returns:** T 118 | 119 | A serialized object result parsed from the response body. 120 | 121 | Defined in: [lib/PetitioResponse.ts:62](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L62) 122 | 123 | ___ 124 | 125 | ### text 126 | 127 | ▸ **text**(`encoding?`: BufferEncoding): *string* 128 | 129 | #### Parameters: 130 | 131 | Name | Type | Default value | 132 | :------ | :------ | :------ | 133 | `encoding` | BufferEncoding | "utf8" | 134 | 135 | **Returns:** *string* 136 | 137 | The response body decoded as as a string from the buffer, using either the encoding specified in `encoding` or UTF-8 by default.. 138 | 139 | Defined in: [lib/PetitioResponse.ts:70](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L70) 140 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/pkg/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "petitio" 4 | slug: "/pkg" 5 | sidebar_label: "Readme" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | A zero-dependency HTTP library designed to be simple, fast, and type-strong. 13 | 14 | Credit to [Centra] for inspiration, as Petitio was originally a fork. 15 | 16 | [Centra]: https://github.com/ethanent/centra 17 | 18 | Useful links: 19 | - [Docs](https://helperdiscord.github.io/petitio) 20 | - [Usage examples](https://github.com/helperdiscord/petitio/tree/master/USAGE.md) 21 | - [Benchmarks / comparison](https://github.com/helperdiscord/petitio/tree/master/PERFORMANCE.md) 22 | 23 | ## What's with the name? 24 | 25 | *"Petitio"* is a hybrid between the French word for "small" ("petit"), and the 26 | Latin word for "request" ("petitio"). This library was originally called 27 | `@helperdiscord/centra`, but we changed it to evolve beyond our status as a 28 | Centra fork and set out to create the smallest and fastest high-level Node HTTP 29 | wrapper available. 30 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/pkg/interfaces/petitiorequest.timeoutoptions.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest.timeoutoptions" 3 | title: "Interface: TimeoutOptions" 4 | sidebar_label: "TimeoutOptions" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Interface: TimeoutOptions 10 | 11 | [PetitioRequest](../modules/petitiorequest.md).TimeoutOptions 12 | 13 | **`see`** [Undici ClientOptions timeout documentation](https://github.com/nodejs/undici/blob/main/docs/api/Client.md#parameter-clientoptions) 14 | 15 | ## Properties 16 | 17 | ### bodyTimeout 18 | 19 | • `Optional` **bodyTimeout**: *number* 20 | 21 | Defined in: [lib/PetitioRequest.ts:24](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L24) 22 | 23 | ___ 24 | 25 | ### headersTimeout 26 | 27 | • `Optional` **headersTimeout**: *number* 28 | 29 | Defined in: [lib/PetitioRequest.ts:25](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L25) 30 | 31 | ___ 32 | 33 | ### keepAliveTimeout 34 | 35 | • `Optional` **keepAliveTimeout**: *number* 36 | 37 | Defined in: [lib/PetitioRequest.ts:26](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L26) 38 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/pkg/modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "modules" 3 | title: "petitio" 4 | sidebar_label: "Table of contents" 5 | hide_table_of_contents: true 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | ## Table of contents 13 | 14 | ### Modules 15 | 16 | - [Petitio](modules/petitio.md) 17 | - [PetitioRequest](modules/petitiorequest.md) 18 | - [PetitioResponse](modules/petitioresponse.md) 19 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/pkg/modules/petitio.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitio" 3 | title: "Module: Petitio" 4 | sidebar_label: "Petitio" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: Petitio 10 | 11 | ## Properties 12 | 13 | ### export= 14 | 15 | • **export=**: (`url`: *string* \| *URL*, `method`: [*HTTPMethod*](petitiorequest.md#httpmethod)) => [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | #### Type declaration: 18 | 19 | ▸ (`url`: *string* \| *URL*, `method?`: [*HTTPMethod*](petitiorequest.md#httpmethod)): [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 20 | 21 | **`see`** [PetitioRequest.constructor](../classes/petitiorequest.petitiorequest-1.md#constructor) 22 | 23 | #### Parameters: 24 | 25 | Name | Type | Default value | Description | 26 | :------ | :------ | :------ | :------ | 27 | `url` | *string* \| *URL* | - | The URL to start composing a request for. | 28 | `method` | [*HTTPMethod*](petitiorequest.md#httpmethod) | "GET" | - | 29 | 30 | **Returns:** [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 31 | 32 | The Petitio request instance for your URL. 33 | 34 | Defined in: [index.ts:5](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/index.ts#L5) 35 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/pkg/modules/petitiorequest.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest" 3 | title: "Module: PetitioRequest" 4 | sidebar_label: "PetitioRequest" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioRequest 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioRequest](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | ### Interfaces 18 | 19 | - [TimeoutOptions](../interfaces/petitiorequest.timeoutoptions.md) 20 | 21 | ## Type aliases 22 | 23 | ### HTTPMethod 24 | 25 | Ƭ **HTTPMethod**: *GET* \| *POST* \| *PATCH* \| *DELETE* \| *PUT* 26 | 27 | Accepted HTTP methods (currently only supports up to HTTP/1.1). 28 | 29 | Defined in: [lib/PetitioRequest.ts:19](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L19) 30 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-plugin-content-docs/version-1.2.0/pkg/modules/petitioresponse.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse" 3 | title: "Module: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioResponse 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioResponse](../classes/petitioresponse.petitioresponse-1.md) 16 | -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-theme-classic/footer.json: -------------------------------------------------------------------------------- 1 | { 2 | "link.title.Docs": { 3 | "message": "Docs", 4 | "description": "The title of the footer links column with title=Docs in the footer" 5 | }, 6 | "link.title.More": { 7 | "message": "More", 8 | "description": "The title of the footer links column with title=More in the footer" 9 | }, 10 | "link.item.label.Getting Started": { 11 | "message": "Getting Started", 12 | "description": "The label of footer link with label=Getting Started linking to docs/guides/getting-started" 13 | }, 14 | "link.item.label.API Reference": { 15 | "message": "API Reference", 16 | "description": "The label of footer link with label=API Reference linking to docs/pkg/index" 17 | }, 18 | "link.item.label.Blog": { 19 | "message": "Blog", 20 | "description": "The label of footer link with label=Blog linking to blog" 21 | }, 22 | "link.item.label.GitHub": { 23 | "message": "GitHub", 24 | "description": "The label of footer link with label=GitHub linking to https://github.com/helperdiscord/petitio" 25 | }, 26 | "copyright": { 27 | "message": "Copyright © 2021 helperdiscord. Built with Docusaurus and TypeDoc.", 28 | "description": "The footer copyright" 29 | } 30 | } -------------------------------------------------------------------------------- /docs/i18n/en-gb/docusaurus-theme-classic/navbar.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": { 3 | "message": "Petitio Docs", 4 | "description": "The title in the navbar" 5 | }, 6 | "item.label.Docs": { 7 | "message": "Docs", 8 | "description": "Navbar item with label Docs" 9 | }, 10 | "item.label.Blog": { 11 | "message": "Blog", 12 | "description": "Navbar item with label Blog" 13 | }, 14 | "item.label.Performance": { 15 | "message": "Performance", 16 | "description": "Navbar item with label Performance" 17 | }, 18 | "item.label.GitHub": { 19 | "message": "GitHub", 20 | "description": "Navbar item with label GitHub" 21 | } 22 | } -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "petitio-docs", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "clear": "docusaurus clear", 12 | "serve": "docusaurus serve", 13 | "write-translations": "docusaurus write-translations", 14 | "write-heading-ids": "docusaurus write-heading-ids", 15 | "lint": "run-p lint:**", 16 | "lint:site": "eslint src --ext js --fix" 17 | }, 18 | "dependencies": { 19 | "@docusaurus/core": "2.0.0-alpha.72", 20 | "@docusaurus/preset-classic": "2.0.0-alpha.72", 21 | "@mdx-js/react": "^1.6.21", 22 | "prop-types": "^15.7.2", 23 | "react": "^17.0.1", 24 | "react-dom": "^17.0.1" 25 | }, 26 | "devDependencies": { 27 | "@kludge-cs/eslint-config-js": "^1.2.0", 28 | "@types/prop-types": "^15.7.3", 29 | "docusaurus-plugin-typedoc": "^0.12.0", 30 | "eslint": "^7.23.0", 31 | "eslint-plugin-json": "^2.1.2", 32 | "eslint-plugin-react": "^7.23.1", 33 | "npm-run-all": "^4.1.5", 34 | "typedoc": "^0.20.34", 35 | "typedoc-plugin-markdown": "^3.6.0", 36 | "typescript": "^4.2.3" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /docs/sidebars.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable node/no-unpublished-require */ 2 | module.exports = { 3 | docs: [ 4 | { 5 | type: "category", 6 | label: "Guides", 7 | items: [ 8 | "guides/getting-started", 9 | "guides/basic-examples" 10 | ] 11 | }, 12 | { 13 | type: "category", 14 | label: "Metrics", 15 | items: [ 16 | "metrics/performance" 17 | ] 18 | }, 19 | { 20 | type: "category", 21 | label: "API Reference", 22 | items: require("./typedoc-sidebar") 23 | } 24 | ] 25 | }; 26 | -------------------------------------------------------------------------------- /docs/src/components/feature.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable node/no-missing-import */ 2 | import { arrayOf, shape, string } from "prop-types"; 3 | import React from "react"; 4 | import clsx from "../lib/clsx"; 5 | import styles from "./feature.module.css"; 6 | import useBaseUrl from "@docusaurus/useBaseUrl"; 7 | 8 | export default function Feature({imageUrl, title, description}) { 9 | const imgUrl = useBaseUrl(imageUrl); 10 | let image; 11 | if (imgUrl) { 12 | image = 13 | 14 | ; 15 | } 16 | return ( 17 | 18 | {image} 19 | {title} 20 | {description} 21 | 22 | ); 23 | } 24 | Feature.propTypes = { 25 | imageUrl: string.isRequired, 26 | title: string.isRequired, 27 | description: string.isRequired 28 | }; 29 | 30 | 31 | export function FeatureList({features}) { 32 | return 33 | 34 | 35 | {features.map((props, idx) => )} 36 | 37 | 38 | ; 39 | } 40 | FeatureList.propTypes = { 41 | features: arrayOf(shape(Feature.propTypes)) 42 | }; 43 | -------------------------------------------------------------------------------- /docs/src/components/feature.module.css: -------------------------------------------------------------------------------- 1 | .features { 2 | display: flex; 3 | align-items: center; 4 | padding: 2rem 0; 5 | width: 100%; 6 | } 7 | 8 | .featureImage { 9 | height: 200px; 10 | width: 200px; 11 | } 12 | -------------------------------------------------------------------------------- /docs/src/components/version.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable node/no-missing-import */ 2 | import { any, arrayOf, instanceOf, string } from "prop-types"; 3 | import Link from "@docusaurus/Link"; 4 | import React from "react"; 5 | import Translate from "@docusaurus/Translate"; 6 | 7 | export default function Version({ key, label, path, notes }) { 8 | return 9 | {label} 10 | 11 | 12 | 15 | Documentation 16 | 17 | 18 | 19 | 20 | 21 | 24 | Release Notes 25 | 26 | 27 | 28 | ; 29 | } 30 | Version.propTypes = { 31 | key: any, 32 | label: string.isRequired, 33 | path: string.isRequired, 34 | notes: string.isRequired 35 | }; 36 | 37 | export function VersionTable({ id, label, description, children }) { 38 | return 39 | {label} 40 | {description} 41 | 42 | {children} 43 | 44 | ; 45 | } 46 | VersionTable.propTypes = { 47 | id: any, 48 | label: string, 49 | description: string, 50 | children: arrayOf(instanceOf(Version)) 51 | }; 52 | -------------------------------------------------------------------------------- /docs/src/css/custom.css: -------------------------------------------------------------------------------- 1 | /* Infima variables */ 2 | :root { 3 | --ifm-color-primary: #cd152a; 4 | --ifm-color-primary-dark: #ab1d2e; 5 | --ifm-color-primary-darker: #9b1a2a; 6 | --ifm-color-primary-darkest: #8d1826; 7 | --ifm-color-primary-light: #d1283b; 8 | --ifm-color-primary-lighter: #e34457; 9 | --ifm-color-primary-lightest: #e65566; 10 | --ifm-code-font-size: 95%; 11 | } 12 | 13 | .docusaurus-highlight-code-line { 14 | background-color: #542f33; 15 | display: block; 16 | margin: 0 calc(-1 * var(--ifm-pre-padding)); 17 | padding: 0 var(--ifm-pre-padding); 18 | } 19 | -------------------------------------------------------------------------------- /docs/src/lib/clsx.js: -------------------------------------------------------------------------------- 1 | // Very minimal class concatenation, inspired by clsx. 2 | export default function clsx(...args) { 3 | return args.filter((entry) => Boolean(entry)).join(" "); 4 | } 5 | -------------------------------------------------------------------------------- /docs/src/pages/index.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable node/no-missing-import */ 2 | import { FeatureList } from "../components/feature"; 3 | import Layout from "@theme/Layout"; 4 | import Link from "@docusaurus/Link"; 5 | import React from "react"; 6 | import Translate from "@docusaurus/Translate"; 7 | import clsx from "../lib/clsx"; 8 | import styles from "./index.module.css"; 9 | import useBaseUrl from "@docusaurus/useBaseUrl"; 10 | import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; 11 | 12 | // TODO: add more features, change logo, use remark plugins, add documentation searching 13 | const features = [ 14 | { 15 | title: 18 | Warp Speed, Mr. Sulu 19 | , 20 | description: 24 | performance 25 | }}> 26 | {`Petitio is the fastest mainstream high-level HTTP library 27 | available on NPM. Check {performance} for more details.`} 28 | 29 | } 30 | ]; 31 | const STYLE = { 32 | BANNER: clsx("hero hero--primary", styles.heroBanner), 33 | BUTTON: clsx( 34 | "button button--outline button--secondary button--lg", 35 | styles.getStarted 36 | ) 37 | }; 38 | 39 | export default function Home() { 40 | const context = useDocusaurusContext(); 41 | const {siteConfig = {}} = context; 42 | 43 | return ( 44 | 45 | 46 | 47 | {siteConfig.title} 48 | 49 | 50 | Zero-dependency HTTP library designed to be simple, 51 | fast, and type-strong. 52 | 53 | 54 | 55 | 56 | 57 | Get Started 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | ); 68 | } 69 | -------------------------------------------------------------------------------- /docs/src/pages/index.module.css: -------------------------------------------------------------------------------- 1 | .heroBanner { 2 | padding: 4rem 0; 3 | text-align: center; 4 | position: relative; 5 | overflow: hidden; 6 | } 7 | 8 | @media screen and (max-width: 966px) { 9 | .heroBanner { 10 | padding: 2rem; 11 | } 12 | } 13 | 14 | .buttons { 15 | display: flex; 16 | align-items: center; 17 | justify-content: center; 18 | } 19 | -------------------------------------------------------------------------------- /docs/src/pages/versions.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable node/no-missing-import */ 2 | import Version, { VersionTable } from "../components/version"; 3 | import { useLatestVersion, useVersions } from "@theme/hooks/useDocs"; 4 | import Layout from "@theme/Layout"; 5 | import React from "react"; 6 | import Translate from "@docusaurus/Translate"; 7 | import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; 8 | 9 | // eslint-disable-next-line max-lines-per-function 10 | export default function Versions() { 11 | const { siteConfig } = useDocusaurusContext(); 12 | const versions = useVersions(); 13 | const latest = useLatestVersion(); 14 | const current = versions.find((version) => version.name === "current"); 15 | const past = versions.filter( 16 | (version) => version !== latest && version.name !== "current" 17 | ); 18 | const repoUrl = `https://github.com/${siteConfig.organizationName}/${siteConfig.projectName}`; 19 | 20 | let latestTable; 21 | if (latest) { 22 | latestTable = Latest} 24 | description={ 25 | Here you can find the documentation for the 26 | latest released version. 27 | }> 28 | 32 | ; 33 | } 34 | 35 | let currentTable; 36 | if (current !== latest) { 37 | currentTable = 40 | Next (Unreleased) 41 | 42 | } 43 | description={ 44 | Here you can find the documentation for the unreleased 45 | bleeding-edge version. 46 | }> 47 | 51 | ; 52 | } 53 | 54 | let pastTable; 55 | if (past.length) { 56 | pastTable = 59 | Previous versions (unmaintained) 60 | 61 | } 62 | description={ 63 | Here you can find the documentation for archived versions. 64 | }> 65 | {past.map((version) => )} 66 | ; 67 | } 68 | return ( 69 | 70 | 71 | 72 | 73 | Petitio documentation versions 74 | 75 | 76 | {latestTable} 77 | {currentTable} 78 | {pastTable} 79 | 80 | 81 | ); 82 | } 83 | -------------------------------------------------------------------------------- /docs/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helperdiscord/petitio/a450fbcc1e6e93e61069bfdabce099afd4ea4933/docs/static/.nojekyll -------------------------------------------------------------------------------- /docs/static/img/docusaurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helperdiscord/petitio/a450fbcc1e6e93e61069bfdabce099afd4ea4933/docs/static/img/docusaurus.png -------------------------------------------------------------------------------- /docs/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helperdiscord/petitio/a450fbcc1e6e93e61069bfdabce099afd4ea4933/docs/static/img/favicon.ico -------------------------------------------------------------------------------- /docs/static/img/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/axios.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 388 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 388 kB 17 | 388 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/got.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.33 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.33 MB 17 | 1.33 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/isomorphic-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 216 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 216 kB 17 | 216 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/node-fetch.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 155 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 155 kB 17 | 155 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/petitio.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 41.2 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 41.2 kB 17 | 41.2 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/phin.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 23.0 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 23.0 kB 17 | 23.0 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/r2.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 201 kB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 201 kB 17 | 201 kB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/request.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 3.84 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 3.84 MB 17 | 3.84 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/assets/superagent.svg: -------------------------------------------------------------------------------- 1 | 2 | install size: 1.70 MB 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | install size 15 | install size 16 | 1.70 MB 17 | 1.70 MB 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/guides/getting-started.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "getting-started" 3 | title: "Getting Started" 4 | --- 5 | 6 | **Note: Petitio supports both `require` and `import` syntax out of the box, so 7 | there's no need to do any pesky ESM or CJS hacks.** 8 | 9 | ## Basic Usage 10 | 11 | The [default export] of Petitio is a wrapper function for [PetitioRequest], 12 | meaning all you need to get started is as follows: 13 | 14 | ```typescript 15 | import petitio from "petitio"; 16 | 17 | const request = petitio("https://example.com"); 18 | ``` 19 | 20 | That instantiates a [PetitioRequest] for `example.com`. Simple right? 21 | Let's take a look at how we send requests and work with responses. 22 | 23 | ```typescript 24 | const result = await request.send().text(); 25 | // equivalent to 26 | const result = await request.text(); 27 | ``` 28 | 29 | Fast and clean. Beautiful, even. But how does that work? 30 | [PetitioRequest#send][send] instructs Petitio to send the current 31 | [PetitioRequest] and returns a [PetitioResponse] with the response data, and 32 | then [PetitioResponse#text][response-text] parses the response body from 33 | a buffer to a string. The shorthand form of this is 34 | [PetitioRequest#text][request-text], which sends the request and invokes text 35 | parsing for you in one call. 36 | 37 | That's the basics covered! Check out some more [usage examples], or read 38 | through our [other guides]. 39 | 40 | [default export]: ../pkg/modules/petitio#export 41 | [PetitioRequest]: ../pkg/classes/petitiorequest.petitiorequest-1 42 | [PetitioResponse]: ../pkg/classes/petitioresponse.petitioresponse-1 43 | [send]: ../pkg/classes/petitiorequest.petitiorequest-1#send 44 | [response-text]: ../pkg/classes/petitioresponse.petitioresponse-1#text 45 | [request-text]: ../pkg/classes/petitiorequest.petitiorequest-1#text 46 | [usage examples]: https://github.com/helperdiscord/petitio/tree/master/USAGE.md 47 | [other guides]: ../ 48 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "index" 4 | slug: "/" 5 | sidebar_label: "Home" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # Petitio Reference 11 | 12 | Here you will find the documentation for Petitio. 13 | 14 | We suggest you start by checking out the following: 15 | - [The "Getting Started" guide](/docs/guides/getting-started) 16 | - [The API Reference](/docs/pkg) 17 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/metrics/performance.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "performance" 3 | title: "Performance" 4 | --- 5 | 6 | ## Preface 7 | 8 | These results are collected from [a suite] managed by helperdiscord and verified 9 | by Kludge Cyber Systems. Anyone may add to them with the results from their own 10 | system, and they are kept up to date with at least two samples from each 11 | version. 12 | 13 | [a suite]: https://github.com/helperdiscord/http-benchmarks 14 | 15 | ## Package Size 16 | 17 | Here you can see how efficient Petitio is in contrast to its competitors in 18 | terms of bundle size. 19 | 20 | 21 | Results table 22 | 23 | | Package | Size | 24 | |------------------|--------------------------------------------------------------------------------------------------------------------------------| 25 | | request | [](https://packagephobia.now.sh/result?p=request@2.88.2) | 26 | | superagent | [](https://packagephobia.now.sh/result?p=superagent@6.1.0) | 27 | | got | [](https://packagephobia.now.sh/result?p=got@11.8.2) | 28 | | axios | [](https://packagephobia.now.sh/result?p=axios@0.21.1) | 29 | | isomorphic-fetch | [](https://packagephobia.now.sh/result?p=isomorphic-fetch@3.0) | 30 | | r2 | [](https://packagephobia.now.sh/result?p=r2@2.0.1) | 31 | | node-fetch | [](https://packagephobia.now.sh/result?p=node-fetch@2.6.1) | 32 | | petitio | [](https://packagephobia.now.sh/result?p=petitio@1.1.0) | 33 | | phin | [](https://packagephobia.now.sh/result?p=phin@3.5.1) | 34 | 35 | 36 | ## Package Speed 37 | 38 | If you wish to verify these results, you may run [the suite] yourself. You can 39 | find the latest results [here]. 40 | 41 | [the suite]: https://github.com/helperdiscord/http-benchmarks 42 | [here]: https://github.com/helperdiscord/http-benchmarks/blob/main/RESULTS.md 43 | 44 | Format key for package results: `N ops/sec ±MOE% (R)` where N is the number of 45 | operations per second achieved, MOE is the margin of error, and R is the number 46 | of times the test was ran. 47 | 48 | | CPU | Governor | Fastest | `got` | `request` | `node-fetch` | `centra` | `https` | `petitio (undici)` | `petitio (http)` | 49 | |:-------------:|:-----------:|:-----------------------:|:-------------------:|:-------------------:|:-------------------:|:-------------------:|:--------------------:|:-----------------------:|:-------------------:| 50 | | [i7-7700k][1] | Performance | `petitio (undici)` | 2,119 ±4.93% (70) | 5,786 ±6.52% (69) | 6,011 ±3.94% (70) | 9,245 ±4.46% (74) | 10,275 ±0.84% (83) | 16,349 ±2.44% (85) | N/A. | 51 | | [i7-6600U][2] | Performance | `petitio (undici)` | 1,913 ±0.54% (2073) | 4,738 ±0.59% (2068) | 4,393 ±0.56% (2072) | 5,800 ±0.92% (2068) | 5,912 ±0.55% (2071) | 13,088 ±0.54% (2074) | 7,301 ±0.53% (2073) | 52 | 53 | [1]: https://github.com/tbnritzdoge 54 | [2]: https://github.com/nytelife26 55 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/pkg/classes/petitioresponse.petitioresponse-1.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse.petitioresponse-1" 3 | title: "Class: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Class: PetitioResponse 10 | 11 | [PetitioResponse](../modules/petitioresponse.md).PetitioResponse 12 | 13 | ## Constructors 14 | 15 | ### constructor 16 | 17 | \+ **new PetitioResponse**(): [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 18 | 19 | **Returns:** [*PetitioResponse*](petitioresponse.petitioresponse-1.md) 20 | 21 | ## Properties 22 | 23 | ### body 24 | 25 | • **body**: *Buffer* 26 | 27 | The response body received from the server. 28 | This is updated in chunks through [PetitioResponse._addChunk](petitioresponse.petitioresponse-1.md#_addchunk), either 29 | from [PetitioRequest.send](petitiorequest.petitiorequest-1.md#send) or directly on a response object from 30 | another source. 31 | 32 | Defined in: [lib/PetitioResponse.ts:12](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L12) 33 | 34 | ___ 35 | 36 | ### headers 37 | 38 | • **headers**: *object* 39 | 40 | The response headers received from the server. 41 | This is updated through [PetitioResponse._parseHeaders](petitioresponse.petitioresponse-1.md#_parseheaders). 42 | 43 | #### Type declaration: 44 | 45 | Defined in: [lib/PetitioResponse.ts:17](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L17) 46 | 47 | ___ 48 | 49 | ### statusCode 50 | 51 | • **statusCode**: *null* \| *number*= null 52 | 53 | The status code received from the server. 54 | This is set only after the response is complete when headers are received 55 | or it can be set manually. 56 | 57 | Defined in: [lib/PetitioResponse.ts:23](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L23) 58 | 59 | ## Methods 60 | 61 | ### \_addChunk 62 | 63 | ▸ **_addChunk**(`chunk`: *Buffer* \| *Uint8Array*): *void* 64 | 65 | This appends data to the body, dynamically reallocating the buffer size 66 | as chunks are added. Therefore, this is currently unsuitable for handling 67 | large responses, as the exact size is allocated in memory as a buffer. 68 | 69 | #### Parameters: 70 | 71 | Name | Type | Description | 72 | :------ | :------ | :------ | 73 | `chunk` | *Buffer* \| *Uint8Array* | The chunk of data to append to the body. | 74 | 75 | **Returns:** *void* 76 | 77 | In place operation with no return. 78 | 79 | Defined in: [lib/PetitioResponse.ts:32](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L32) 80 | 81 | ___ 82 | 83 | ### \_parseHeaders 84 | 85 | ▸ **_parseHeaders**(`headers`: *string*[]): *void* 86 | 87 | #### Parameters: 88 | 89 | Name | Type | Description | 90 | :------ | :------ | :------ | 91 | `headers` | *string*[] | The headers to add. This is done by splitting the array into chunks of two, where the first value becomes the header and the latter becomes its value. This will also append values to the header as an array if it already exists. | 92 | 93 | **Returns:** *void* 94 | 95 | In place operation with no return. 96 | 97 | Defined in: [lib/PetitioResponse.ts:43](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L43) 98 | 99 | ___ 100 | 101 | ### json 102 | 103 | ▸ **json**(`encoding?`: BufferEncoding): T 104 | 105 | #### Type parameters: 106 | 107 | Name | Default | Description | 108 | :------ | :------ | :------ | 109 | `T` | *any* | Type casting parameter for the JSON result. | 110 | 111 | #### Parameters: 112 | 113 | Name | Type | Default value | 114 | :------ | :------ | :------ | 115 | `encoding` | BufferEncoding | "utf8" | 116 | 117 | **Returns:** T 118 | 119 | A serialized object result parsed from the response body. 120 | 121 | Defined in: [lib/PetitioResponse.ts:62](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L62) 122 | 123 | ___ 124 | 125 | ### text 126 | 127 | ▸ **text**(`encoding?`: BufferEncoding): *string* 128 | 129 | #### Parameters: 130 | 131 | Name | Type | Default value | 132 | :------ | :------ | :------ | 133 | `encoding` | BufferEncoding | "utf8" | 134 | 135 | **Returns:** *string* 136 | 137 | The response body decoded as as a string from the buffer, using either the encoding specified in `encoding` or UTF-8 by default.. 138 | 139 | Defined in: [lib/PetitioResponse.ts:70](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioResponse.ts#L70) 140 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/pkg/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "index" 3 | title: "petitio" 4 | slug: "/pkg" 5 | sidebar_label: "Readme" 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | A zero-dependency HTTP library designed to be simple, fast, and type-strong. 13 | 14 | Credit to [Centra] for inspiration, as Petitio was originally a fork. 15 | 16 | [Centra]: https://github.com/ethanent/centra 17 | 18 | Useful links: 19 | - [Docs](https://helperdiscord.github.io/petitio) 20 | - [Usage examples](https://github.com/helperdiscord/petitio/tree/master/USAGE.md) 21 | - [Benchmarks / comparison](https://github.com/helperdiscord/petitio/tree/master/PERFORMANCE.md) 22 | 23 | ## What's with the name? 24 | 25 | *"Petitio"* is a hybrid between the French word for "small" ("petit"), and the 26 | Latin word for "request" ("petitio"). This library was originally called 27 | `@helperdiscord/centra`, but we changed it to evolve beyond our status as a 28 | Centra fork and set out to create the smallest and fastest high-level Node HTTP 29 | wrapper available. 30 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/pkg/interfaces/petitiorequest.timeoutoptions.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest.timeoutoptions" 3 | title: "Interface: TimeoutOptions" 4 | sidebar_label: "TimeoutOptions" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Interface: TimeoutOptions 10 | 11 | [PetitioRequest](../modules/petitiorequest.md).TimeoutOptions 12 | 13 | **`see`** [Undici ClientOptions timeout documentation](https://github.com/nodejs/undici/blob/main/docs/api/Client.md#parameter-clientoptions) 14 | 15 | ## Properties 16 | 17 | ### bodyTimeout 18 | 19 | • `Optional` **bodyTimeout**: *number* 20 | 21 | Defined in: [lib/PetitioRequest.ts:24](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L24) 22 | 23 | ___ 24 | 25 | ### headersTimeout 26 | 27 | • `Optional` **headersTimeout**: *number* 28 | 29 | Defined in: [lib/PetitioRequest.ts:25](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L25) 30 | 31 | ___ 32 | 33 | ### keepAliveTimeout 34 | 35 | • `Optional` **keepAliveTimeout**: *number* 36 | 37 | Defined in: [lib/PetitioRequest.ts:26](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L26) 38 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/pkg/modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "modules" 3 | title: "petitio" 4 | sidebar_label: "Table of contents" 5 | hide_table_of_contents: true 6 | custom_edit_url: null 7 | hide_title: true 8 | --- 9 | 10 | # petitio 11 | 12 | ## Table of contents 13 | 14 | ### Modules 15 | 16 | - [Petitio](modules/petitio.md) 17 | - [PetitioRequest](modules/petitiorequest.md) 18 | - [PetitioResponse](modules/petitioresponse.md) 19 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/pkg/modules/petitio.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitio" 3 | title: "Module: Petitio" 4 | sidebar_label: "Petitio" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: Petitio 10 | 11 | ## Properties 12 | 13 | ### export= 14 | 15 | • **export=**: (`url`: *string* \| *URL*, `method`: [*HTTPMethod*](petitiorequest.md#httpmethod)) => [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | #### Type declaration: 18 | 19 | ▸ (`url`: *string* \| *URL*, `method?`: [*HTTPMethod*](petitiorequest.md#httpmethod)): [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 20 | 21 | **`see`** [PetitioRequest.constructor](../classes/petitiorequest.petitiorequest-1.md#constructor) 22 | 23 | #### Parameters: 24 | 25 | Name | Type | Default value | Description | 26 | :------ | :------ | :------ | :------ | 27 | `url` | *string* \| *URL* | - | The URL to start composing a request for. | 28 | `method` | [*HTTPMethod*](petitiorequest.md#httpmethod) | "GET" | - | 29 | 30 | **Returns:** [*PetitioRequest*](../classes/petitiorequest.petitiorequest-1.md) 31 | 32 | The Petitio request instance for your URL. 33 | 34 | Defined in: [index.ts:5](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/index.ts#L5) 35 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/pkg/modules/petitiorequest.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitiorequest" 3 | title: "Module: PetitioRequest" 4 | sidebar_label: "PetitioRequest" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioRequest 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioRequest](../classes/petitiorequest.petitiorequest-1.md) 16 | 17 | ### Interfaces 18 | 19 | - [TimeoutOptions](../interfaces/petitiorequest.timeoutoptions.md) 20 | 21 | ## Type aliases 22 | 23 | ### HTTPMethod 24 | 25 | Ƭ **HTTPMethod**: *GET* \| *POST* \| *PATCH* \| *DELETE* \| *PUT* 26 | 27 | Accepted HTTP methods (currently only supports up to HTTP/1.1). 28 | 29 | Defined in: [lib/PetitioRequest.ts:19](https://github.com/helperdiscord/petitio/blob/c80cdcc/src/lib/PetitioRequest.ts#L19) 30 | -------------------------------------------------------------------------------- /docs/versioned_docs/version-1.2.0/pkg/modules/petitioresponse.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "petitioresponse" 3 | title: "Module: PetitioResponse" 4 | sidebar_label: "PetitioResponse" 5 | custom_edit_url: null 6 | hide_title: true 7 | --- 8 | 9 | # Module: PetitioResponse 10 | 11 | ## Table of contents 12 | 13 | ### Classes 14 | 15 | - [PetitioResponse](../classes/petitioresponse.petitioresponse-1.md) 16 | -------------------------------------------------------------------------------- /docs/versioned_sidebars/version-1.2.0-sidebars.json: -------------------------------------------------------------------------------- 1 | { 2 | "version-1.2.0/docs": [ 3 | { 4 | "collapsed": true, 5 | "type": "category", 6 | "label": "Guides", 7 | "items": [ 8 | { 9 | "type": "doc", 10 | "id": "version-1.2.0/guides/getting-started" 11 | } 12 | ] 13 | }, 14 | { 15 | "collapsed": true, 16 | "type": "category", 17 | "label": "Metrics", 18 | "items": [ 19 | { 20 | "type": "doc", 21 | "id": "version-1.2.0/metrics/performance" 22 | } 23 | ] 24 | }, 25 | { 26 | "collapsed": true, 27 | "type": "category", 28 | "label": "API Reference", 29 | "items": [ 30 | { 31 | "type": "doc", 32 | "id": "version-1.2.0/pkg/index" 33 | }, 34 | { 35 | "type": "doc", 36 | "id": "version-1.2.0/pkg/modules" 37 | }, 38 | { 39 | "collapsed": true, 40 | "type": "category", 41 | "label": "Modules", 42 | "items": [ 43 | { 44 | "type": "doc", 45 | "id": "version-1.2.0/pkg/modules/petitio" 46 | }, 47 | { 48 | "type": "doc", 49 | "id": "version-1.2.0/pkg/modules/petitiorequest" 50 | }, 51 | { 52 | "type": "doc", 53 | "id": "version-1.2.0/pkg/modules/petitioresponse" 54 | } 55 | ] 56 | }, 57 | { 58 | "collapsed": true, 59 | "type": "category", 60 | "label": "Classes", 61 | "items": [ 62 | { 63 | "type": "doc", 64 | "id": "version-1.2.0/pkg/classes/petitiorequest.petitiorequest-1" 65 | }, 66 | { 67 | "type": "doc", 68 | "id": "version-1.2.0/pkg/classes/petitioresponse.petitioresponse-1" 69 | } 70 | ] 71 | }, 72 | { 73 | "collapsed": true, 74 | "type": "category", 75 | "label": "Interfaces", 76 | "items": [ 77 | { 78 | "type": "doc", 79 | "id": "version-1.2.0/pkg/interfaces/petitiorequest.timeoutoptions" 80 | } 81 | ] 82 | } 83 | ] 84 | } 85 | ] 86 | } 87 | -------------------------------------------------------------------------------- /docs/versions.json: -------------------------------------------------------------------------------- 1 | [ 2 | "1.2.0" 3 | ] 4 | -------------------------------------------------------------------------------- /esbuild.config.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line 2 | const esbuild = require("esbuild"); 3 | 4 | esbuild.build({ 5 | bundle: true, 6 | entryPoints: ["./src/index.ts"], 7 | external: ["_http_common"], 8 | format: "cjs", 9 | minify: true, 10 | outfile: "./dist/index.js", 11 | platform: "node", 12 | target: "node12", 13 | tsconfig: "tsconfig.json" 14 | }).catch((err) => { 15 | throw (err); 16 | }); 17 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from "@jest/types"; 2 | 3 | // eslint-disable-next-line @typescript-eslint/require-await 4 | export default async (): Promise => ({ 5 | coverageProvider: "v8", 6 | displayName: "unit test", 7 | preset: "ts-jest", 8 | testEnvironment: "node", 9 | testRunner: "jest-circus/runner", 10 | testMatch: ["/tests/**/*.test.ts"], 11 | globalSetup: "/tests/global-setup.ts", 12 | globalTeardown: "/tests/global-teardown.ts", 13 | globals: { 14 | "ts-jest": { 15 | tsconfig: "/tests/tsconfig.json" 16 | } 17 | } 18 | }); 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "petitio", 3 | "version": "1.4.0", 4 | "description": "Zero-dependency HTTP library designed to be simple, fast, and type-strong.", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "files": [ 8 | "dist", 9 | "!dist/*.tsbuildinfo" 10 | ], 11 | "exports": { 12 | "require": "./dist/index.js", 13 | "import": "./dist/index.mjs" 14 | }, 15 | "scripts": { 16 | "prepare": "husky install", 17 | "prepack": "npm run build", 18 | "build": "run-p build:*", 19 | "build:main": "node esbuild.config.js", 20 | "build:types": "tsc -b src", 21 | "postbuild": "gen-esm-wrapper dist/index.js dist/index.mjs", 22 | "docs": "typedoc src/**/*.ts --entryPoints src/index.ts ./tsconfig.json", 23 | "test": "jest", 24 | "test:coverage": "jest --coverage", 25 | "lint": "eslint src tests --ext ts --fix", 26 | "lint:docs": "eslint docs --fix", 27 | "bench": "node benchmarks/index.mjs" 28 | }, 29 | "author": "Vetlix doge Nytelife26 (https://github.com/Nytelife26)", 30 | "license": "MIT", 31 | "repository": { 32 | "type": "git", 33 | "url": "https://github.com/helperdiscord/petitio.git" 34 | }, 35 | "devDependencies": { 36 | "@jest/types": "^26.6.2", 37 | "@kludge-cs/bench-utils": "^1.0.1", 38 | "@kludge-cs/eslint-config-js": "^1.2.0", 39 | "@kludge-cs/eslint-config-ts": "^2.0.0", 40 | "@semantic-release/changelog": "^5.0.1", 41 | "@semantic-release/commit-analyzer": "^8.0.1", 42 | "@semantic-release/git": "^9.0.0", 43 | "@semantic-release/github": "^7.2.3", 44 | "@semantic-release/npm": "^7.1.3", 45 | "@semantic-release/release-notes-generator": "^9.0.2", 46 | "@types/jest": "^26.0.23", 47 | "@types/node": "^15.0.3", 48 | "@typescript-eslint/eslint-plugin": "^4.23.0", 49 | "@typescript-eslint/parser": "^4.23.0", 50 | "abort-controller": "^3.0.0", 51 | "benchmark": "^2.1.4", 52 | "esbuild": "^0.11.20", 53 | "eslint": "^7.26.0", 54 | "eslint-plugin-react": "^7.23.2", 55 | "gen-esm-wrapper": "^1.1.1", 56 | "husky": "^5.1.3", 57 | "jest": "^26.6.3", 58 | "jest-circus": "^26.6.3", 59 | "lint-staged": "^11.0.0", 60 | "node-abort-controller": "^2.0.0", 61 | "npm-run-all": "^4.1.5", 62 | "semantic-release": "^17.4.3", 63 | "ts-jest": "^26.5.6", 64 | "ts-node": "^9.1.1", 65 | "typedoc": "^0.20.36", 66 | "typescript": "^4.2.4", 67 | "undici": "^3.3.6" 68 | }, 69 | "engines": { 70 | "node": ">=12.3.0" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /release.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | branches: ["main"], 3 | plugins: [ 4 | "@semantic-release/commit-analyzer", 5 | "@semantic-release/release-notes-generator", 6 | "@semantic-release/changelog", 7 | "@semantic-release/npm", 8 | "@semantic-release/github", 9 | [ 10 | "@semantic-release/git", 11 | { 12 | assets: [ 13 | "package.json", 14 | "package-lock.json", 15 | "CHANGELOG.md" 16 | ], 17 | message: "chore: release ${nextRelease.version}\n\n${nextRelease.notes}" 18 | } 19 | ] 20 | ] 21 | }; 22 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module Petitio 3 | */ 4 | import { HTTPMethod, PetitioRequest } from "./lib/PetitioRequest"; 5 | import { PetitioResponse } from "./lib/PetitioResponse"; 6 | import { URL } from "url"; 7 | 8 | /** 9 | * @param {(string | URL)} url The URL to start composing a request for. 10 | * @param {HTTPMethod} [method="GET"] The HTTP method to use. 11 | * @return {PetitioRequest} The Petitio request instance for your URL. 12 | * @see [[PetitioRequest.constructor]] 13 | */ 14 | // @ts-ignore typescript is technically right that this shouldn't exist but it is the only export of a useable class, whereas the rest are for easy of use type-wise 15 | export = function petitio(url: URL | string, method: HTTPMethod = "GET"): PetitioRequest { 16 | return new PetitioRequest(url, method); 17 | } 18 | 19 | export { HTTPMethod, PetitioRequest, PetitioResponse }; 20 | -------------------------------------------------------------------------------- /src/lib/PetitioResponse.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module PetitioResponse 3 | */ 4 | 5 | export class PetitioResponse { 6 | /** 7 | * The response body received from the server. 8 | * This is updated through [[PetitioResponse._addBody]], either 9 | * from [[PetitioRequest.send]] or directly on a response object from 10 | * another source. 11 | */ 12 | public body!: Buffer; 13 | /** 14 | * The response headers received from the server. 15 | * This is updated through [[PetitioResponse._parseHeaders]]. 16 | */ 17 | public headers: { [k: string]: any } = {}; 18 | /** 19 | * The status code received from the server. 20 | * This is set only after the response is complete when headers are received 21 | * or it can be set manually. 22 | */ 23 | public statusCode: number | null = null; 24 | 25 | /** 26 | * This takes the data chunks and creates a Buffer, and it sets 27 | * that buffer as the body. 28 | * @param {*} chunks The body to set for the response. 29 | * @return {*} In place operation with no return. 30 | */ 31 | public _addBody(chunks: Buffer[] | Uint8Array[]) { 32 | const length = this.headers["content-length"]; 33 | this.body = Buffer.concat(chunks, length ? Number(length) : undefined); 34 | } 35 | 36 | /** 37 | * @param {*} headers The headers to add. This is done by splitting the 38 | * array into chunks of two, where the first value becomes the header and 39 | * the latter becomes its value. This will also append values to the header 40 | * as an array if it already exists. 41 | * @return {*} In place operation with no return. 42 | */ 43 | public _parseHeaders(headers: string[]) { 44 | for (let idx = 1; idx < headers.length; idx += 2) { 45 | const key = headers[idx - 1].toLowerCase(); 46 | let val = this.headers[key]; 47 | if (val) { 48 | if (!Array.isArray(val)) { 49 | val = [val]; 50 | this.headers[key] = val; 51 | } 52 | val.push(headers[idx]); 53 | } else this.headers[key] = headers[idx]; 54 | } 55 | } 56 | 57 | /** 58 | * @template T Type casting parameter for the JSON result. 59 | * @param {BufferEncoding} [encoding="utf8"] The encoding to use when parsing the response body. 60 | * @return {T} A serialized object result parsed from the response body. 61 | */ 62 | public json(encoding: BufferEncoding = "utf8"): T { 63 | return JSON.parse(this.body.toString(encoding)); 64 | } 65 | 66 | /** 67 | * @param {BufferEncoding} [encoding="utf8"] The encoding to use. 68 | * @return {string} The response body decoded as as a string from the buffer, using either the encoding specified in `encoding` or UTF-8 by default.. 69 | */ 70 | public text(encoding: BufferEncoding = "utf8"): string { 71 | return this.body.toString(encoding); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/PetitioRequest.test.ts: -------------------------------------------------------------------------------- 1 | import type { HTTPMethod, TimeoutOptions } from "../src/lib/PetitioRequest"; 2 | import AbortController from "node-abort-controller"; 3 | import { Client } from "undici"; 4 | import { URL as NURL } from "url"; 5 | import { PetitioRequest } from "../src/lib/PetitioRequest"; 6 | import { Readable } from "stream"; 7 | import qs from "querystring"; 8 | 9 | function url(host = "localhost:8080", method = "http") { 10 | return `${method}://${host}`; 11 | } 12 | 13 | describe("Constructor", () => { 14 | test("GIVEN invalid protocol THEN THROW", () => { 15 | expect.assertions(2); 16 | 17 | function func() { 18 | return new PetitioRequest(url("localhost:8080", "wss")); 19 | } 20 | 21 | expect(func).toThrow("Bad URL protocol: wss:"); 22 | expect(func).toThrow(Error); 23 | }); 24 | 25 | test("GIVEN passed url string THEN use native url", () => { 26 | expect.assertions(2); 27 | 28 | const reqOne = new PetitioRequest(new NURL(url())); 29 | const reqTwo = new PetitioRequest(url()); 30 | 31 | expect(reqOne.url instanceof NURL).toEqual(true); 32 | expect(reqTwo.url instanceof NURL).toEqual(true); 33 | }); 34 | }); 35 | 36 | describe("Abort Controller", () => { 37 | test("GIVEN passed controller THEN use controller", () => { 38 | expect.assertions(1); 39 | 40 | const controller = new AbortController(); 41 | 42 | const request = new PetitioRequest(url()).signal(controller); 43 | 44 | expect(request.controller).toEqual(controller); 45 | }); 46 | }); 47 | 48 | describe("Undici Options", () => { 49 | const key = "pipelining"; 50 | const val = 10; 51 | const options = { "pipelining": val }; 52 | 53 | test("GIVEN undici option parameters THEN set options", () => { 54 | expect.assertions(1); 55 | 56 | const req = new PetitioRequest(url()).option(key, val); 57 | expect(req.coreOptions[key]).toEqual(val); 58 | }); 59 | 60 | test("GIVEN undici options object THEN set options", () => { 61 | expect.assertions(1); 62 | 63 | const req = new PetitioRequest(url()).option(options); 64 | expect(req.coreOptions[key]).toEqual(val); 65 | }); 66 | }); 67 | 68 | describe("Undici Client", () => { 69 | const client = new Client(url()); 70 | 71 | test("GIVEN passed client THEN set client", () => { 72 | const req = new PetitioRequest(url()).client(client); 73 | 74 | expect(req.kClient).toEqual(client); 75 | }); 76 | 77 | test("IF keepalive passed THEN set client persistence", () => { 78 | expect.assertions(1); 79 | 80 | const req = new PetitioRequest(url()).client(client, true); 81 | 82 | expect(req.keepClient).toEqual(true); 83 | }); 84 | }); 85 | 86 | describe("Request Body", () => { 87 | const body = { hi: "hello" }; 88 | const text = "hi"; 89 | const bodyString = JSON.stringify(body); 90 | const bodyBuffer = Buffer.from(bodyString); 91 | const bodyStream = Readable.from(text, {objectMode: false}); 92 | 93 | test("GIVEN passed body string THEN set body / headers", () => { 94 | expect.assertions(3); 95 | 96 | const req = new PetitioRequest(url()).body(body); 97 | 98 | expect(req.data).toEqual(bodyString); 99 | expect(req.reqHeaders["content-type"]).toEqual("application/json"); 100 | expect(req.reqHeaders["content-length"]).toEqual(Buffer.byteLength(bodyString).toString()); 101 | }); 102 | 103 | test("GIVEN passed explicit json body THEN set body / headers", () => { 104 | expect.assertions(3); 105 | 106 | const req = new PetitioRequest(url()).body(body, "json"); 107 | 108 | expect(req.data).toEqual(bodyString); 109 | expect(req.reqHeaders["content-type"]).toEqual("application/json"); 110 | expect(req.reqHeaders["content-length"]).toEqual(Buffer.byteLength(bodyString).toString()); 111 | }); 112 | 113 | test("GIVEN passed stream body THEN set body", () => { 114 | expect.assertions(3); 115 | 116 | const req = new PetitioRequest(url()).body(bodyStream, "stream"); 117 | 118 | expect(req.data).toEqual(bodyStream); 119 | expect(req.reqHeaders["content-type"]).toBeUndefined(); 120 | expect(req.reqHeaders["content-length"]).toBeUndefined(); 121 | }); 122 | 123 | test("GIVEN passed form body THEN set body / headers", () => { 124 | expect.assertions(3); 125 | 126 | const query = qs.stringify(body); 127 | const req = new PetitioRequest(url()).body(body, "form"); 128 | 129 | expect(req.data).toEqual(query); 130 | expect(req.reqHeaders["content-type"]).toEqual("application/x-www-form-urlencoded"); 131 | expect(req.reqHeaders["content-length"]).toEqual(Buffer.byteLength(query).toString()); 132 | }); 133 | 134 | test("GIVEN passed buffer body THEN set body / headers", () => { 135 | expect.assertions(3); 136 | 137 | const req = new PetitioRequest(url()).body(bodyBuffer); 138 | 139 | expect(req.data).toEqual(bodyBuffer); 140 | expect(req.reqHeaders["content-type"]).toBeUndefined(); 141 | expect(req.reqHeaders["content-length"]).toEqual(Buffer.byteLength(bodyBuffer).toString()); 142 | }); 143 | }); 144 | 145 | describe("Query Parameters", () => { 146 | const QS = [ 147 | ["test", "test1"], 148 | ["test1", "test"] 149 | ]; 150 | const OQS = Object.fromEntries(QS); 151 | 152 | test("GIVEN query param pair THEN transmit query", async () => { 153 | expect.assertions(1); 154 | 155 | const request = new PetitioRequest(url("localhost:8080/get-echo")); 156 | const response = await request 157 | .query("test", "test1") 158 | .query("test1", "test") 159 | .json<{ args: Record }>(); 160 | 161 | expect(response.args).toEqual(OQS); 162 | }); 163 | 164 | test("GIVEN query params object THEN transmit query", async () => { 165 | expect.assertions(1); 166 | 167 | const request = new PetitioRequest(url("localhost:8080/get-echo")); 168 | const response = await request 169 | .query(OQS) 170 | .json<{ args: Record }>(); 171 | 172 | expect(response.args).toEqual(OQS); 173 | }); 174 | }); 175 | 176 | describe("Request Headers", () => { 177 | const h1 = { hi: "hello" }; 178 | const h2 = Object.entries(h1)[0]; 179 | 180 | test("GIVEN headers object THEN set headers", () => { 181 | expect.assertions(1); 182 | 183 | const request = new PetitioRequest(url()).header(h1); 184 | 185 | expect(request.reqHeaders).toEqual(h1); 186 | }); 187 | 188 | test("GIVEN header pair THEN set headers", () => { 189 | expect.assertions(1); 190 | 191 | const request = new PetitioRequest(url()).header(h2[0], h2[1]); 192 | 193 | expect(request.reqHeaders).toEqual(h1); 194 | }); 195 | }); 196 | 197 | 198 | describe("URL", () => { 199 | test("GIVEN method path THEN set path", () => { 200 | expect.assertions(1); 201 | 202 | const path = "test"; 203 | const req = new PetitioRequest(url()) 204 | .path(path); 205 | 206 | expect(req.url.pathname).toEqual(`/${path}`); 207 | }); 208 | 209 | test("GIVEN constructor path THEN set path", () => { 210 | expect.assertions(1); 211 | 212 | const path = "test"; 213 | const req = new PetitioRequest(url(`localhost:8080/${path}`)); 214 | 215 | expect(req.url.pathname).toEqual(`/${path}`); 216 | }); 217 | 218 | test("GIVEN method THEN set method", () => { 219 | expect.assertions(18); 220 | 221 | const methods: HTTPMethod[] = [ 222 | "GET", 223 | "HEAD", 224 | "POST", 225 | "OPTIONS", 226 | "PUT", 227 | "DELETE", 228 | "TRACE", 229 | "CONNECT", 230 | "PATCH" 231 | ]; 232 | for (const method of methods) { 233 | const reqOne = new PetitioRequest(url()).method(method); 234 | const reqTwo = new PetitioRequest(url(), method); 235 | 236 | expect(reqOne.httpMethod).toEqual(method); 237 | expect(reqTwo.httpMethod).toEqual(method); 238 | } 239 | }); 240 | }); 241 | 242 | describe("Timeout", () => { 243 | const timeout = 1000; 244 | 245 | test("GIVEN timeout AND no method THEN use body timeout", () => { 246 | expect.assertions(1); 247 | 248 | const req = new PetitioRequest(url()) 249 | .timeout(timeout); 250 | 251 | expect(req.timeoutOptions.bodyTimeout).toEqual(timeout); 252 | }); 253 | 254 | test("GIVEN timeout AND method THEN use timeout pair", () => { 255 | expect.assertions(3); 256 | 257 | const timeouts: Array = [ 258 | "bodyTimeout", 259 | "headersTimeout", 260 | "keepAliveTimeout" 261 | ]; 262 | 263 | for (const timeoutKey of timeouts) { 264 | const req = new PetitioRequest(url()).timeout(timeoutKey, timeout); 265 | 266 | expect(req.timeoutOptions[timeoutKey]).toEqual(timeout); 267 | } 268 | }); 269 | }); 270 | 271 | describe("Sending", () => { 272 | const obj = { test: "test1", test1: "test" }; 273 | 274 | test("GIVEN passed json THEN MATCH received raw", async () => { 275 | expect.assertions(1); 276 | 277 | const response = await new PetitioRequest(url("localhost:8080/get-echo")) 278 | .query("test", "test1") 279 | .query("test1", "test") 280 | .raw(); 281 | const json = JSON.parse(response.toString()); 282 | expect(json.args).toEqual(obj); 283 | }); 284 | 285 | test("GIVEN passed json THEN MATCH received text", async () => { 286 | expect.assertions(1); 287 | 288 | const response = await new PetitioRequest("http://localhost:8080/get-echo") 289 | .query("test", "test1") 290 | .query("test1", "test") 291 | .text(); 292 | 293 | const json = JSON.parse(response); 294 | expect(json.args).toEqual(obj); 295 | }); 296 | 297 | test("GIVEN passed json THEN MATCH received text", async () => { 298 | expect.assertions(1); 299 | 300 | const res = await new PetitioRequest("http://localhost:8080/get-echo") 301 | .query("test", "test1") 302 | .query("test1", "test") 303 | .json(); 304 | 305 | expect(res.args).toEqual(obj); 306 | }); 307 | 308 | test("IF existing client THEN use existing", async () => { 309 | expect.assertions(1); 310 | 311 | const client = new Client(url()); 312 | const spy = jest.spyOn(client, "dispatch"); 313 | 314 | await new PetitioRequest(url()) 315 | .client(client) 316 | .send(); 317 | 318 | expect(spy).toHaveBeenCalledTimes(1); 319 | }); 320 | 321 | test("IF invalid THEN THROW", () => { 322 | expect.assertions(1); 323 | const URL = new NURL("http://nothing.nowhere"); 324 | 325 | return expect(new PetitioRequest(URL).send()).rejects.toThrow(); 326 | }); 327 | }); 328 | -------------------------------------------------------------------------------- /tests/PetitioResponse.test.ts: -------------------------------------------------------------------------------- 1 | import { PetitioRequest } from "../src/lib/PetitioRequest"; 2 | import { PetitioResponse } from "../src/lib/PetitioResponse"; 3 | 4 | function url(host = "localhost:8080", method = "http") { 5 | return `${method}://${host}`; 6 | } 7 | 8 | describe("Response Parsing", () => { 9 | test("GIVEN json from request THEN parse", async () => { 10 | expect.assertions(1); 11 | 12 | const json = { 13 | id: 0, 14 | title: "in collaboration we trust", 15 | body: "melius simul quam solus" 16 | }; 17 | const request = new PetitioRequest(url("localhost:8080/json-test")); 18 | const response = await request.json(); 19 | 20 | expect(response).toEqual(json); 21 | }); 22 | }); 23 | 24 | describe("Response Formats", () => { 25 | const text = "hi"; 26 | const buffer = Buffer.from(text); 27 | const encoded = buffer.toString("base64"); 28 | 29 | test("GIVEN buffer THEN parse json", () => { 30 | expect.assertions(1); 31 | 32 | const data = { hi: "hello" }; 33 | const buf = Buffer.from(JSON.stringify(data)); 34 | const res = new PetitioResponse(); 35 | res._addBody([buf]); 36 | const final = res.json(); 37 | 38 | expect(final).toEqual(data); 39 | }); 40 | 41 | test("GIVEN buffer THEN parse text", () => { 42 | expect.assertions(1); 43 | 44 | const res = new PetitioResponse(); 45 | res._addBody([buffer]); 46 | const final = res.text(); 47 | 48 | expect(final).toEqual(text); 49 | }); 50 | 51 | test("GIVEN buffer THEN parse encoded text", () => { 52 | expect.assertions(1); 53 | 54 | const res = new PetitioResponse(); 55 | res._addBody([buffer]); 56 | const final = res.text("base64"); 57 | 58 | expect(final).toEqual(encoded); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /tests/global-setup.ts: -------------------------------------------------------------------------------- 1 | import type { IncomingMessage, ServerResponse } from "http"; 2 | import { URL } from "url"; 3 | import { createServer } from "http"; 4 | 5 | const JSON_RESPONSE = JSON.stringify({ 6 | id: 0, 7 | title: "in collaboration we trust", 8 | body: "melius simul quam solus" 9 | }); 10 | 11 | function requestHandler( 12 | req: IncomingMessage, 13 | res: ServerResponse 14 | ) { 15 | const url = new URL(`http://${req.headers.host}${req.url || ""}`); 16 | switch (url.pathname) { 17 | case "/get-echo": { 18 | res.writeHead(200, req.headers); 19 | return res.end(JSON.stringify({ 20 | args: Object.fromEntries(url.searchParams.entries()), 21 | headers: req.headers, 22 | url: url.href 23 | })); 24 | } 25 | case "/json-test": { 26 | res.writeHead(200, { 27 | "Content-Type": "application/json", 28 | "Content-Length": Buffer.byteLength(JSON_RESPONSE).toString() 29 | }); 30 | return res.end(JSON_RESPONSE); 31 | } 32 | default: { 33 | res.writeHead(200); 34 | res.end("No command specified"); 35 | } 36 | } 37 | } 38 | 39 | export default function globalSetup() { 40 | // @ts-expect-error: Jest & Node type merging creates conflict 41 | global.__SERVER__ = createServer(requestHandler); 42 | // @ts-expect-error: Jest & Node type merging creates conflict 43 | global.__SERVER__.listen(8080); 44 | } 45 | -------------------------------------------------------------------------------- /tests/global-teardown.ts: -------------------------------------------------------------------------------- 1 | export default function globalTeardown() { 2 | // @ts-expect-error: Jest & Node type merging creates conflict 3 | global.__SERVER__.close(); 4 | } 5 | -------------------------------------------------------------------------------- /tests/parseHeaders.test.ts: -------------------------------------------------------------------------------- 1 | import { PetitioResponse } from "../src/lib/PetitioResponse"; 2 | 3 | describe("parseHeaders", () => { 4 | describe("run", () => { 5 | test("parsed headers array SHOULD match header object", () => { 6 | const headersArray = ["a", "1", "b", "2", "c", "3"]; 7 | const parsedHeaders = {"a": "1", "b": "2", "c": "3"}; 8 | 9 | expect.assertions(1); 10 | 11 | const res = new PetitioResponse(); 12 | res._parseHeaders(headersArray); 13 | 14 | expect(res.headers).toEqual(parsedHeaders); 15 | }); 16 | 17 | test("IF overlapping headers THEN concatenate", () => { 18 | const headersArray = ["a", "1", "b", "2", "c", "3", "a", "4"]; 19 | const parsedHeaders = {"a": ["1", "4"], "b": "2", "c": "3"}; 20 | 21 | expect.assertions(1); 22 | 23 | const res = new PetitioResponse(); 24 | res._parseHeaders(headersArray); 25 | 26 | expect(res.headers).toEqual(parsedHeaders); 27 | }); 28 | 29 | test("IF headers exist THEN array", () => { 30 | const headersArray = ["b", "2", "c", "3", "a", "4"]; 31 | const parsedHeaders = {"a": ["1", "4"], "b": "2", "c": "3"}; 32 | 33 | expect.assertions(1); 34 | 35 | const res = new PetitioResponse(); 36 | res.headers = {"a": "1"}; 37 | res._parseHeaders(headersArray); 38 | 39 | expect(res.headers).toEqual(parsedHeaders); 40 | }); 41 | 42 | test("IF array headers exist THEN append", () => { 43 | const headersArray = ["b", "2", "c", "3", "a", "5"]; 44 | const parsedHeaders = {"a": ["1", "4", "5"], "b": "2", "c": "3"}; 45 | 46 | expect.assertions(1); 47 | 48 | const res = new PetitioResponse(); 49 | res.headers = {"a": ["1", "4"]}; 50 | res._parseHeaders(headersArray); 51 | 52 | expect(res.headers).toEqual(parsedHeaders); 53 | }); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json" 3 | } -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "includes": ["src", "tests", "*.config.*", "docs"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2015", 4 | "module": "CommonJS", 5 | "declaration": true, 6 | "outDir": "dist", 7 | "resolveJsonModule": true, 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "esModuleInterop": true, 11 | "experimentalDecorators": true, 12 | "emitDecoratorMetadata": true, 13 | "lib": ["es2019"] 14 | } 15 | } 16 | --------------------------------------------------------------------------------
{description}
49 | 50 | Zero-dependency HTTP library designed to be simple, 51 | fast, and type-strong. 52 | 53 |