http.js 799 B

1234567891011121314151617181920212223
  1. const methodSelect = document.getElementById('request-method')
  2. const requestUrlInput = document.getElementById('request-url')
  3. const requestBodyInput = document.getElementById('request-body')
  4. document.getElementById('make-request').addEventListener('click', function () {
  5. const method = methodSelect.value || 'GET'
  6. const url = requestUrlInput.value || ''
  7. const options = {
  8. url: url,
  9. method: method
  10. }
  11. let body = requestBodyInput.value || ''
  12. if ((body.startsWith('{') && body.endsWith('}')) || (body.startsWith('[') && body.endsWith(']'))) {
  13. body = JSON.parse(body)
  14. } else if (body.startsWith('/') || body.match(/\S:\//g)) {
  15. options.bodyAsFile = true
  16. }
  17. options.body = body
  18. window.__TAURI__.http.request(options).then(registerResponse).catch(registerResponse)
  19. })