json-server
-
yarn add json-server -s 下载
-
修改package.json文件,添加"serve": “json-server ./mock/cookbook.json -p 9000 -w”
-
运行 yarn serve
-
GET /posts?_page=7&_limit=20 //查询7页,一页返回十条数据
-
GET /posts?_sort=views&_order=asc //按升序排序 GET /posts?_sort=views&_order=asc //按降序排序
-
GET /posts?_start=20&_end=30 //筛选从第20条到30条 GET /posts/1/comments?_start=20&_end=30 GET /posts/1/comments?_start=20&_limit=10
-
GET /posts?views_gte=10&views_lte=20 //筛选出大于10小于20的 GET /posts?id_ne=1 //不等1的
-
GET /posts?title_like=server //模糊匹配,
HTTP请求
get 获取数据
post 提交数据,添加,增量,
patch 打补丁 只修改传入的内容
put 修改,给什么就修改成什么,其他的全都被删除掉了
delete 删除数据
options 先试探检查连接是否通 再修改
head 只提交首部字段 没有数据 少用
graphql
中台 整合接口 用户管理,用户健全
本地搭建环境 node
express /koa
看版本 npm view webpack version
改变默认版本 nvm alias default 版本号
浏览器端使用import
npx 作用 :没有模块,会帮助装好。配置临时文件夹,使用完会删除
搭建express环境
-
npm install express
-
npm install -g express-generator
-
express
-
express -e
-
选择y
-
会下载包
-
yarn
-
yarn start 启动
-
浏览器输入localhost:3000启动
-
yarn add express-graphql -s
-
yarn add graphql
-
创建server.js文件
const express = require( 'express') const {graphqlHTTP} = require('express-graphql') const schema = require('./MyGraphQLSchema') const app = express() app.use( '/graphql', //中间件 graphqlHTTP({ schema, graphiql: true, }), ) //监听端口 app.listen(4040)
-
yarn add graphqlHTTP -s
-
创建MyGraphQLSchema.js文件
//解构三个对象 const { GraphQLSchema, GraphQLObjectType, GraphQLString, } =require ('graphql'); //先new一个GraphQLSchema(设计模式)对象 //query查询,再new一个对象类型对象,定义名字,字段 var schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'RootQueryType', fields: { hello: { type: GraphQLString, resolve() { return 'world'; }, }, }, }), }); module.exports= schema
-
nodemon server.js 启动服务
-
在浏览器输入http://localhost:4040/graphql
-
npm install json-server
-
json-server ./mock/movie.json -p 9000 -w
-
nvm list 查看nodejs版本号
-
nvm install v14.15.0
-
npm view webpack versions 查看webpack版本号
-
yarn add body-parse
-
nvm --help
-
设置默认版本 nvm alias default v14.15.0 ( nvm use v14.15.0)
-
npx http-server npx:如果没有文件就会帮忙装,创建临时文件,不用的时候把临时文件夹自动删除 如果当前文件夹bin下有东西,会先运行bin下的东西
-
localhost:8080
-
import 要在浏览器端使用。要在scrip里面加type=module
-
清除缓存 ctrl+shift+delete
-
commonjs规范在浏览器实现
-
浏览器端不支持require 支持es6的import做法:在scrip里面加type=module,并且所有文件都要加扩展名
-
localhost:8080
-
import 要在浏览器端使用。要在scrip里面加type=module
-
清除缓存 ctrl+shift+delete
-
commonjs规范在浏览器实现
-
浏览器端不支持require 支持es6的import做法:在scrip里面加type=module,并且所有文件都要加扩展名