#! /bin/bash
# 环境
# 定义http请求的动词
POST="POST"
DELETE="DELETE"
# 查看spring server提供的方法
echo "RESTful is:"
curl http://localhost:8080 # crul命令行
echo "\n请输入url:" # \n是换行符
read url_name # 从屏幕上输入一个字符串并赋值给url_name
base_url="http://localhost:8080/" #最基本的url
your_url="$base_url$url_name" #拼接字符串
echo "拼接成的url是: $your_url"
echo "看一下我们可以测试除了REST之外还有哪儿些方法和所有的数据:"
curl $your_url
echo "\n开始测试REST方法: 请输入http的请求方法"
read method #读取屏幕上输入的方法
#if-else条件判断语句
if test $method = $POST #用test命令判断两个字符串是否相等
then
curl -i -X POST -H "Content-Type:application/json" -d '{"firstName":"Frodo","lastName":"Baggins","emailAddress":"mengynzhi@yunzhiclub"}' http://localhost:8080/people # 发送http请求保存数据
echo "\n保存数据成功"
elif test $method = $DELETE
then
echo "查看所有的数据"
curl $your_url
echo "\n输入想要删除的数据id"
read id
delete_url="$your_url/$id" #拼接删除的url
delete="-X DELETE $delete_url" #拼接删除命令
curl $delete #执行删除命令
fi