API(get/post)
来源:互联网 发布:java import include 编辑:程序博客网 时间:2024/05/16 19:22
//index.js 入口
//引入express框架(需安装)
const express = require('express');
//创建一个App
const app = express();
//使用中间件
const bodyParser = require('body-parser');
app.use(bodyParser.json());
//配置请求路由
const backProduct = require('./BackProduct');//引入BackProduct.js
app.post('/api/backProduct',backProduct);
const getNoTice = require('./GetNoTice');//引入GetNoTice.js
app.get('/api/getNoTice',getNoTice) ;
//开启监听
const server = app.listen(3000, function () {
console.log('开启监听');
});
//post请求(req.body)
//BackProduct.js
module.exports = (req,res)=>{
if (req.body.token == 'xxxx'){
const r = {
success:true,
}
res.json(r);
const mingxi = {
id:502,
productID:306,
productName:'Nike',
productCode:548,
productColorID:23,
productColorName:'red',
productSizeID:42,
productSizeName:'大码',
count:001,
price:100,
totalPrice:200,
type:3,
};
console.log(mingxi);
}
else {
const r = {
success:false,
message:'退货失败',
}
res.json(r);
}
}
//get请求(req.query)
//GetNoTice.js
console.log('收到请求');
//req.body是app提交上来的数据
console.log(req.query); //
if (req.query.token!=null) {
const p={
id:1,
title:'zzz',
content:'zzzzzzzz',
date:'2017-6-8',
type:0
}
res.json(p);
}
else {
const p = {
success:false,
message:'获取通知失败',
}
res.json(p);
}
//是服务器需要返回给App的数据
}
- API(get/post)
- API调用:GET、POST
- API Request Get和Post
- PHP(CURL)POST/GET数据调用API简单示例
- WebClient 通过get和post请求api
- [API]common http get and post
- api中的GET和POST的区别
- C#中GET、POST请求API
- WebClient 通过get和post请求api
- learning jQuery 学习笔记十六(+jQuery 1.4.1 API)-- AJAX----$.get() & $.post()
- GET与POST(0212)
- HttpClient(Post和Get)
- 新东方API demo中get和post请求的写法
- restful,RESTful API 设计,GET/PUT/DELETE/POST
- web api 中get和post一些经验总结
- HBase rest API - GET、PUT/POST、的使用
- Python SOAP API, HTTP POST and HTTP GET
- Restful Web Api Get 和 Post 请求的参数设置
- 接入-分布式任务调度平台XXL-JOB
- Python Base
- 51nod 1424 零树
- 层模式
- Oracle:触发器
- API(get/post)
- 关于Java中的继承,包括重写、构造器、访问权限、构造过程等知识总结
- webstorm项目运行到apache服务器
- POJ
- 微积分公式大全
- 使用UGUI ScrollView 排列不规则内容元素实现滑动效果
- 分析SYSTEMSTATS DUMP
- 关于时间处理
- org.springframework.orm.hibernate4.HibernateSystemException: could not deserialize