Nubank API 开源项目教程

Nubank API 开源项目教程

nubank-apiNuBank API - Not related to Nu Pagamentos S.A.项目地址:https://gitcode.com/gh_mirrors/nub/nubank-api

1. 项目的目录结构及介绍

nubank-api/
├── README.md
├── package.json
├── src/
│   ├── index.ts
│   ├── api/
│   │   ├── auth.ts
│   │   ├── bill.ts
│   │   └── utils.ts
│   └── types/
│       └── index.ts
└── tsconfig.json
  • README.md: 项目说明文档。
  • package.json: 项目依赖和脚本配置文件。
  • src/: 源代码目录。
    • index.ts: 项目入口文件。
    • api/: API 相关模块。
      • auth.ts: 认证模块。
      • bill.ts: 账单查询模块。
      • utils.ts: 工具函数模块。
    • types/: 类型定义文件。
  • tsconfig.json: TypeScript 配置文件。

2. 项目的启动文件介绍

项目的启动文件是 src/index.ts。该文件主要负责初始化 API 连接和提供对外的接口。以下是 index.ts 的主要内容:

import { initAuth } from './api/auth';
import { getBillDetails } from './api/bill';

export async function start() {
  const authToken = await initAuth('your-cpf', 'your-password');
  const billDetails = await getBillDetails(authToken);
  console.log(billDetails);
}

start();
  • initAuth: 初始化认证,获取认证令牌。
  • getBillDetails: 使用认证令牌获取账单详情。

3. 项目的配置文件介绍

项目的配置文件主要是 package.jsontsconfig.json

package.json

{
  "name": "nubank-api",
  "version": "1.0.0",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "ts-node": "^9.1.1",
    "typescript": "^4.1.3"
  }
}
  • scripts: 定义了启动脚本 start,使用 ts-node 运行 src/index.ts
  • dependencies: 项目依赖,包括 axios 用于 HTTP 请求,ts-node 用于直接运行 TypeScript 文件,typescript 用于 TypeScript 编译。

tsconfig.json

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}
  • compilerOptions: TypeScript 编译选项。
    • target: 编译目标为 ES6。
    • module: 使用 commonjs 模块系统。
    • outDir: 编译输出目录为 dist
    • strict: 开启严格模式。
    • esModuleInterop: 支持 ES 模块 interoperability。
  • include: 包含 src 目录下的所有文件。

nubank-apiNuBank API - Not related to Nu Pagamentos S.A.项目地址:https://gitcode.com/gh_mirrors/nub/nubank-api

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

田桥桑Industrious

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值