JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 26
  • Score
    100M100P100Q46988F
  • License MIT License

Package Exports

  • @forgepack/request
  • @forgepack/request/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@forgepack/request) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Request

GitHub stars

Node.js npm React TypeScript

Start a new project

mkdir package-name
cd package-name
npm init

.json file created:

{
  "name": "package-name",
  "version": "1.0.0",
  "description": "Package Description",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": ["palavra-chave1", "palavra-chave2"],
  "author": "Name",
  "license": "MIT"
}

Publicar no npm

# Login no npm
npm login
# Constrói
npm run build
# Simula publicação
npm pack
# Publicar o pacote, na primeira vez
npm publish --access public

Atualizar versões

Quando fizer mudanças:

npm version patch  # 1.0.0 -> 1.0.1
npm version minor  # 1.0.0 -> 1.1.0
npm version major  # 1.0.0 -> 2.0.0

npm publish

Publish at

https://github.com/forgepack
https://www.npmjs.com/org/forgepack
https://dev.to/
https://codesandbox.io/
https://stackblitz.com/

Uso pelo consumidor (Vite, React, Next, Node, etc.)

📦 Instalação

npm install @forgepack/request

⚙️ Configuração Básica

// 1. Configure o cliente da API
import { createApiClient } from "@forgepack/request"

export const api = createApiClient({
  baseURL: "https://api.meuservico.com",
  onUnauthorized: () => window.location.href = "/login",
  onForbidden: () => window.location.href = "/notAllowed"
})

// 2. Configure o provedor de autenticação
import { AuthProvider } from '@forgepack/request'

function App() {
  return (
    <AuthProvider api={api}>
      <YourApp />
    </AuthProvider>
  )
}

🚀 Principais Recursos

  • 🔐 Autenticação JWT - Login automático com interceptors
  • 🛡️ Proteção de Rotas - Componente RequireAuth baseado em roles
  • 📊 Hook de Requisições - useRequest com paginação e busca
  • ⚡ Operações CRUD - Funções prontas para create, read, update, delete
  • 🔑 Gerenciamento de Tokens - Validação e decodificação automática
  • 📱 Responsivo - Estados de loading, erro e paginação

📚 Complete Documentation

For detailed examples, usage guides, and API references, please visit: Complete Documentation

🎯 Quick Example

// Authentication hook
const { loginUser, isAuthenticated, role } = useAuth()

// Hook for paginated requests
const { response, loading, error } = useRequest(api, 'users', {
  page: 0, size: 10, value: 'busca'
})

// Route protection
<RequireAuth allowedRoles={['ADMIN']}>
  <AdminPanel />
</RequireAuth>

Developers

Gadelha TI

License

This project is licensed under the MIT License - see the MIT LICENSE file for details.

MIT License

Copyright (c) 2024 Gadelha TI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Request

⭐ Did you like the project? Leave a star! ⭐