rest.js 3.8 KB

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