rest copy.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //Items GET 获取全部内容
  2. async function getPet(){
  3. let response = await fetch("http://web2023.fmode.cn:9999/parse/classes/Items?", {
  4. "headers": {
  5. "accept": "*/*",
  6. "accept-language": "zh-CN,zh;q=0.9",
  7. "if-none-match": "W/\"7e0-mc6U9HFyuJHJIduZnf+lM36E+qs\"",
  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("Items")
  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",
  42. "if-none-match": "W/\"7e0-mc6U9HFyuJHJIduZnf+lM36E+qs\"",
  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. // //Items Post 创建数据
  63. // fetch("http://web2023.fmode.cn:9999/parse/classes/Items", {
  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": "{\"category\": \"二手交易\",\"title\": \"ipad9二手出售\",\"publisher\": \"耶耶\", \n \"headImage\":\"/assets/images/black.png\",\"name\":\"ipad9\",\"amount\":800\n }",
  73. // "method": "POST",
  74. // "mode": "cors",
  75. // "credentials": "omit"
  76. // });
  77. // //Items Put 添加数据
  78. // fetch("http://web2023.fmode.cn:9999/parse/classes/Items/l3XZKsAIPO", {
  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": "{\"location\":\"大学生活动中心\",\"image\":\"/assets/images/ipad9.jpg\",\"content\":\"不可议价\",\"repliesId\":\"6\"}",
  88. // "method": "PUT",
  89. // "mode": "cors",
  90. // "credentials": "omit"
  91. // });
  92. // //Items Detele 删除数据
  93. // fetch("http://web2023.fmode.cn:9999/parse/classes/Items/l3XZKsAIPO", {
  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. // });