项目作者: kiarash8

项目描述 :
HTTP Request Handler
高级语言: TypeScript
项目地址: git://github.com/kiarash8/fetchomech.git
创建时间: 2020-10-28T19:15:08Z
项目社区:https://github.com/kiarash8/fetchomech

开源协议:MIT License

下载


Fetchomech

Fetchomech is a Typescript library for HTTP Request Handler.

Installation

Use the package manager npm to install Fetchomech.

  1. npm install fetchomech

Usage

  1. import Fetchomech from 'fetchomech'
  2. //get example
  3. Fetchomech.Get({
  4. url: 'https://example.com/user/:id/something/:name',
  5. headers: { 'Content-Type': 'application/json' },
  6. pathVariables: {
  7. id: '8',
  8. name: 'kia'
  9. },
  10. queryParams: {
  11. foo1: 'bar1',
  12. foo2: 'bar2'
  13. },
  14. body: null
  15. }).then(res => {
  16. console.log(res)
  17. })
  18. //post example (formData)
  19. var data = new FormData()
  20. data.append('usr', 'kiarash8')
  21. data.append('pwd', '123')
  22. Fetchomech.Post({
  23. url: 'https://example.com/login',
  24. headers: {},
  25. pathVariables: {},
  26. queryParams: {},
  27. body: data
  28. }).then(res => {
  29. console.log(res)
  30. })
  31. //post example (data)
  32. const data = JSON.stringify({
  33. user: 'kiarash8',
  34. pwd: '123'
  35. })
  36. Fetchomech.Post({
  37. url: 'https://postman-echo.com/post',
  38. headers: { 'Content-Type': 'application/json' },
  39. pathVariables: {},
  40. queryParams: {
  41. foo1: 'bar1',
  42. foo2: 'bar2'
  43. },
  44. body: data
  45. }).then(res => {
  46. console.log(res)
  47. })
  48. //put example
  49. var data = new FormData()
  50. data.append('firstname', 'kiarash')
  51. data.append('lastname', 'fereiduni')
  52. Fetchomech.Put({
  53. url: 'https://example.com/user/:id',
  54. headers: {},
  55. pathVariables: {
  56. id: '8'
  57. },
  58. queryParams: {},
  59. body: data
  60. }).then(res => {
  61. console.log(res)
  62. })
  63. //patch example
  64. var data = new FormData()
  65. data.append('firstname', 'kiarash')
  66. Fetchomech.Patch({
  67. url: 'https://example.com/user/:id',
  68. headers: {},
  69. pathVariables: {
  70. id: '8'
  71. },
  72. queryParams: {},
  73. body: data
  74. }).then(res => {
  75. console.log(res)
  76. })
  77. //delete example
  78. Fetchomech.Delete({
  79. url: 'https://example.com/post/:id',
  80. headers: {},
  81. pathVariables: {
  82. id: '8'
  83. },
  84. queryParams: {},
  85. body: null
  86. }).then(res => {
  87. console.log(res)
  88. })

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT