Reac front end for psicometric app

HTTP.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // import axios from 'axios';
  2. import $ from "jquery"
  3. export class HTTP_ {
  4. constructor(url){
  5. this.base_url = 'http://204.48.25.93:8081/users';
  6. this.url = this.base_url + url
  7. // this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345'
  8. this.api = 'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
  9. }
  10. async post(){
  11. try{
  12. let request = fetch(this.api, {
  13. method: 'POST',
  14. mode: 'cors',
  15. // cache: 'no-cache',
  16. headers: {
  17. "Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
  18. "Connection": "keep-alive",
  19. "Content-Type": "application/json",
  20. "Date": new Date().toUTCString(),
  21. "Expires": 0,
  22. "Keep-Alive": "timeout=60",
  23. "Pragma": "no-cache",
  24. "Transfer-Encoding": "chunked",
  25. "Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
  26. "X-Content-Type-Options": "nosniff",
  27. "X-Frame-Options": "DENY",
  28. "X-XSS-Protection": 1
  29. },
  30. // body: body
  31. });
  32. // let response = await request.json();
  33. console.log(await request)
  34. }catch(error) {
  35. console.log(error)
  36. return { status : 0, message : error.message }
  37. }
  38. }
  39. async get_() {
  40. // POST request using fetch with async/await
  41. const requestOptions = {
  42. method: 'POST',
  43. headers : new Headers( {
  44. 'Content-Type': 'application/json',
  45. 'Access-Control-Allow-Origin': '*',
  46. 'Access-Control-Request-Method' : 'POST',
  47. } ),
  48. // body: JSON.stringify({ title: 'React POST Request Example' })
  49. }
  50. let response = await fetch(this.api, requestOptions);
  51. // const data =
  52. console.log(response)
  53. // this.setState({ postId: data.id });
  54. }
  55. async get(){
  56. $.ajax(this.url, {
  57. contentType : 'application/json',
  58. type : 'POST',
  59. onSucces : (res) => console.log(res),
  60. onError : (err) => console.log(err),
  61. })
  62. }
  63. }