json-server

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,并且所有文件都要加扩展名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值