rest.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Pet GET 获取全部宠物
  2. async function getPet(){
  3. let response = await fetch("http://web2023.fmode.cn:9999/parse/classes/Shangpin?", {
  4. "headers": {
  5. "accept": "*/*",
  6. "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  7. "if-none-match": "W/\"1cd-ykQo3crRlIgBOm2OekfhLf5ZHUM\"",
  8. "x-parse-application-id": "dev"
  9. },
  10. "referrer": "http://127.0.0.1:4040/",
  11. "referrerPolicy": "strict-origin-when-cross-origin",
  12. "body": null,
  13. "method": "GET",
  14. "mode": "cors",
  15. "credentials": "omit"
  16. });
  17. // console.log(response)
  18. // return []
  19. if(response?.status=="200"){
  20. let json = await response.json()
  21. // console.log(json)
  22. return json?.results || []
  23. }else{
  24. return []
  25. }
  26. }
  27. async function main(){
  28. // let petList = await getPet()
  29. // console.log(petList)
  30. // let list = await ClassesGet("Pet")
  31. // console.log(list)
  32. let list = await ClassesGet("Student")
  33. console.log(list)
  34. }
  35. main()
  36. // 通过函数封装,实现多个表的查询
  37. async function ClassesGet(className){
  38. let response = await fetch("http://web2023.fmode.cn:9999/parse/classes/"+className, {
  39. "headers": {
  40. "accept": "*/*",
  41. "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  42. "if-none-match": "W/\"19f-gvNjdCzTNrgDv/sckM9+BRABBVY\"",
  43. "x-parse-application-id": "dev"
  44. },
  45. "referrer": "http://127.0.0.1:4040/",
  46. "referrerPolicy": "strict-origin-when-cross-origin",
  47. "body": null,
  48. "method": "GET",
  49. "mode": "cors",
  50. "credentials": "omit"
  51. });
  52. // console.log(response)
  53. // return []
  54. if(response?.status=="200"){
  55. let json = await response.json()
  56. // console.log(json)
  57. return json?.results || []
  58. }else{
  59. return []
  60. }
  61. }
  62. // // Pet POST 创建宠物
  63. // fetch("http://web2023.fmode.cn:9999/parse/classes/Pet", {
  64. // "headers": {
  65. // "accept": "*/*",
  66. // "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  67. // "content-type": "text/plain;charset=UTF-8",
  68. // "x-parse-application-id": "dev"
  69. // },
  70. // "referrer": "http://127.0.0.1:4040/",
  71. // "referrerPolicy": "strict-origin-when-cross-origin",
  72. // "body": '{"name":"小强","type":"蟑螂","price":0.2}',
  73. // "method": "POST",
  74. // "mode": "cors",
  75. // "credentials": "omit"
  76. // });
  77. // // Pet PUT 修改
  78. // fetch("http://web2023.fmode.cn:9999/parse/classes/Pet/bl34OtuBYm", {
  79. // "headers": {
  80. // "accept": "*/*",
  81. // "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  82. // "content-type": "text/plain;charset=UTF-8",
  83. // "x-parse-application-id": "dev"
  84. // },
  85. // "referrer": "http://127.0.0.1:4040/",
  86. // "referrerPolicy": "strict-origin-when-cross-origin",
  87. // "body": "{\"price\":0.09}",
  88. // "method": "PUT",
  89. // "mode": "cors",
  90. // "credentials": "omit"
  91. // });
  92. // // Pet DELETE 删除
  93. // fetch("http://web2023.fmode.cn:9999/parse/classes/Pet/bl34OtuBYm", {
  94. // "headers": {
  95. // "accept": "*/*",
  96. // "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  97. // "x-parse-application-id": "dev"
  98. // },
  99. // "referrer": "http://127.0.0.1:4040/",
  100. // "referrerPolicy": "strict-origin-when-cross-origin",
  101. // "body": null,
  102. // "method": "DELETE",
  103. // "mode": "cors",
  104. // "credentials": "omit"
  105. // });