Giter VIP home page Giter VIP logo

api-open's Introduction

API接口开放平台

背景:前端开发需要用到后台提供的接口,可以考虑一些第三方接口平台,同时可以自己开发一个公共API接口平台。

目的:完成一个开放API接口平台

功能

API接口平台应该具备的功能,参照现有的平台功能,再添加自己需要的内容:

  1. 防止攻击(安全性)
  2. 不能随便调用(限制、开通)
  3. 统计调用次数
  4. 计费
  5. 流量保护
  6. API接入

项目介绍

做一个提供API接口调用的平台。

  • 用户可以注册登录,开通接口调用权限。
  • 用户可以使用接口,并且每次调用会进行统计。
  • 管理员可以发布接口、下线接口、接入接口,以及可视化接口的调用情况、数据。

技术选型

前端:

  • Ant Design Pro
  • Ant Design Procompoments
  • React
  • Umi
  • Umi Request (Axios的封装)

后端:

  • spring boot

  • Spring Boot Starter (SDk开发)

  • 网关、限流、日志实现

  • MySQL 数据库

  • Redis 内存数据库

  • Elasticsearch 搜索引擎

  • 腾讯云 COS 对象存储

工具类

  • Easy Excel 表格处理
  • Hutool 工具库
  • Gson 解析库
  • Apache Commons Lang3 工具类
  • Lombok 注解

业务特性

  • Spring Session Redis 分布式登录
  • 全局请求响应拦截器(记录日志)
  • 全局异常处理器
  • 自定义错误码
  • 封装通用响应类
  • Swagger + Knife4j 接口文档
  • 自定义权限注解 + 全局校验
  • 全局跨域处理
  • 长整数丢失精度解决
  • 多环境配置

单元测试

  • JUnit5 单元测试
  • 示例单元测试类

架构设计

  • 合理分层

快速上手

所有需要修改的地方都标记了 todo,便于大家找到修改的位置~

MySQL 数据库

1)修改 application.yml 的数据库配置为你自己的:

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/my_db
    username: root
    password: root

2)执行 sql/create_table.sql 中的数据库语句,自动创建库表

3)启动项目,访问 http://localhost:8101/api/doc.html 即可打开接口文档,不需要写前端就能在线调试接口了~

Redis 分布式登录

1)修改 application.yml 的 Redis 配置为你自己的:

spring:
  redis:
    database: 1
    host: localhost
    port: 6379
    timeout: 5000
    password: 123456

2)修改 application.yml 中的 session 存储方式:

spring:
  session:
    store-type: redis

3)移除 MainApplication 类开头 @SpringBootApplication 注解内的 exclude 参数:

修改前:

@SpringBootApplication(exclude = {RedisAutoConfiguration.class})

修改后:

@SpringBootApplication

Elasticsearch 搜索引擎

1)修改 application.yml 的 Elasticsearch 配置为你自己的:

spring:
  elasticsearch:
    uris: http://localhost:9200
    username: root
    password: 123456

2)复制 sql/post_es_mapping.json 文件中的内容,通过调用 Elasticsearch 的接口或者 Kibana Dev Tools 来创建索引(相当于数据库建表)

PUT post_v1
{
 参数见 sql/post_es_mapping.json 文件
}

这步不会操作的话需要补充下 Elasticsearch 的知识,或者自行百度一下~

3)开启同步任务,将数据库的帖子同步到 Elasticsearch

找到 job 目录下的 FullSyncPostToEsIncSyncPostToEs 文件,取消掉 @Component 注解的注释,再次执行程序即可触发同步:

// todo 取消注释开启任务
//@Component

api-open's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.