当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

koa-rest-api-boilerplate

授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 巫马自明
操作系统 跨平台
开源组织
适用人群 未知
 软件概览
Koa REST API Boilerplate

Koa REST API Boilerplate

Boilerplate for Node.js Koa RESTful API application with Docker, Swagger, Jest, CodeCov, and Circle CI


Koa REST API Boilerplate is a highly opinionated boilerplate template for building RESTful API application with Koa.

This boilerplate include the following features:

  • Logging to STDOUT/STDERR stream using Pino
  • A super small and optimized Docker image based on Node.js Alpine image
  • Swagger API documentation based on JSDoc
  • Continuous integration and delivery using CircleCI
  • Unit Test and Integration Test along with Test Coverage using Jest testing framework

Getting Started

$ git clone https://github.com/posquit0/koa-rest-api-boilerplate your-project-name
$ cd your-project-name
$ rm -rf .git && git init
$ yarn
$ yarn start

Commands

Run

# Run normally
$ yarn start
# Run the application with nodemon for development
$ yarn dev

Test

# Test
$ yarn test                           # Run all test
$ yarn test:unit                      # Run only unit test
$ yarn test:integration               # Run only integration test
# Test (Watch Mode for development)
$ yarn test:watch                     # Run all test with watch mode
$ yarn test⌚unit                # Run only unit test with watch mode
$ yarn test⌚integration         # Run only integration test with watch mode
# Test Coverage
$ yarn test:coverage                  # Calculate the coverage of all test
$ yarn test:coverage:unit             # Calculate the coverage of unit test
$ yarn test:coverage:integration      # Calculate the coverage of integration test
# Test consistent coding style (Lint)
$ yarn lint                           # Lint all sourcecode
$ yarn lint:app                       # Lint app sourcecode
$ yarn lint:test                      # Lint test sourcecode

Archive

$ yarn pack

Test

All test for this boilerplate uses following tools.

Contributing

This project follows the Contributor Covenant Code of Conduct.

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or ask feature requests.

Self Promotion

Like this project? Please give it a ★ on GitHub! It helps this project a lot.And if you're feeling especially charitable, follow posquit0 on GitHub.

See Also

  • koa-logging - A middleware that logs request and response with Pino.
  • koa-request-id - A middleware that generates a unique Request ID for every incoming HTTP request.
  • koa-http-client - A middleware that attachs HTTP client to communicate with the context during inter-service communications.

License

Provided under the terms of the MIT License.

Copyright © 2017-2019, Byungjin Park.

  • Koa入门教程之示例应用   Koa范例 一个包含一些小示例的存储库,这些示例说明了如何使用Koa创建Web应用程序和其他HTTP服务器。   源码地址 https://github.com/koajs/examples   例子 404 - 404处理 基本身份验证 -中间件基本身份验证示例 博客 -多路线和视图渲染 正文解析 -请求正文解析 撰写 -撰写中间件示例 条件中间件 -显示如何有条件

  • 前端代码: $.ajax({ url:'http://localhost:7777/charts/query', type: 'POST', contentType: 'application/json', data: JSON.stringify({"cccc":"32423423"}), dataType: 'json', success:function (resp) { c

  • import axios from "axios"; const Koa = require("koa"); const app = new Koa(); // // 通过koa内部封装好的上下文进行判断处理 // app.use(async (ctx: { url: string; method: string; body: string }) => { // if (ctx.url =

  • REST_API简介 1.设计概念和准则 网络上的所有事物都可以被抽象为资源 每一个资源都有唯一的资源标识,对资源的操作不会改变这些标识 所有的操作都是无状态的。 2.REST_API中http协议 请求:请求行、消息报头、请求正文 请求方式:get、post、head(请求获取由Request-URI所标识的资源的响应消息报头)、put、delete、options(查询服务器性能,查询与资源相

  • Kubernetes 初始集群创建首个Pod时候报错: Error from server (ServerTimeout): error when creating "hello-world-pod.yaml": No API token found for service account "default", retry after the token is automatically crea

  • 什么是REST API? 微服务之间通过一些轻量级的通信机制进行通信如REST API,那么如何理解REST API呢? 首先要明确一点:REST 实际上只是一种设计风格,它并不是标准。(所以你可以看到网上一大堆的各种最佳实践,设计指南,但是没有人说设计标准) 通俗的讲REST就是: 看Url就知道要什么 看http method就知道干什么 看http status code就知道结果如何 更简

  • 中间件机制 使用koa创建一个基本的 http server const Koa = require('koa'); const http = require('http'); const app = new Koa(); // Create HTTP server. const server = http.createServer(app.callback()); 有点不太理解http.crea

  • 原生路由 网站一般都有多个页面。通过ctx.request.path可以获取用户请求的路径,由此实现简单的路由。 index.js const Koa = require('koa'); const app = new Koa(); const main = ctx => { if (ctx.request.path !== '/') { ctx.response.type = 'h

  • 其实,router这个是一个很重要的内容,用户进行url访问就可以更好的使用 不用router中间件 app.use(async (ctx,next)=>{ if (ctx.path === '/') { ctx.body = 'we are at home!'; } else { await next; } }) app.use(async (ctx,next)=>

  • 功能 解析 PUT / POST 请求中的 body,默认支持的格式有(MIME 可定制): form application/x-www-form-urlencoded json application/json application/json-patch+json application/vnd.api+json application/csp-report text text/plain

  • Koa中常用的中间件: koa-session:让无状态的http拥有状态,基于cookie实现的后台保存信息的session koa-mysql:封装了需要用到的SQL语句 koa-mysql-session:当不想让session存储到内存,而想让session存储到mysql数据库中时使用 koa-router:后台会接受到各种请求的url,路由会根据不同的url来使用不同的处理逻辑。 ko

 相关资料
  • Node - Koa - Typescript Project The main purpose of this repository is to build a good project setup and workflow for writing a Node api rest in TypeScript using KOA and an SQL DB. Koa is a new web fr

  • jackblog api koa版 此为2.2版,基于koa2.2.x 简介 Jackblog 是使用 Node.js + MongoDB + Redis + 其它客户端框架开发的个人博客系统,前后端分离,仿简书模板. 服务端有: express 版 , koa 版 客户端有: angular1.x 版 , angular2.x 版 , react redux 版 , vue 版 移动端有: re

  • graphql-api-koa GraphQL execution and error handling middleware written from scratch for Koa. Setup To install graphql-api-koa and the graphql peer dependency with npm, run: npm install graphql-api-ko

  •     Koa-Vue-Notes-Api This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Frontend Vue GitHub Frontend Vue Demo Frontend React GitHub Fron

  • REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移。 它首次出现在2000年Roy Fielding的博士论文中,Roy Fielding是HTTP规范的主要编写者之一。

  • Storm UI 守护程序提供了一个 REST API, 允许您与 Storm 集群进行交互, 其中包括检索 metrics(度量)数据和配置信息, 启动或停止 topologies(拓扑)的管理操作。 数据格式 该 REST API 返回 JSON 响应并支持 JSONP. 客户端可以传回一个回调查询参数, 以在回调函数中包装 JSON。 REST API allows CORS by defa