File tree Expand file tree Collapse file tree 1 file changed +22
-18
lines changed
Expand file tree Collapse file tree 1 file changed +22
-18
lines changed Original file line number Diff line number Diff line change 11class Url {
2- constructor ( ) {
3- this . url = 'http ://easycode-js.herokuapp.com/myba /users' ;
2+ constructor ( accountName ) {
3+ this . url = `https ://easycode-js.herokuapp.com/${ accountName } /users` ;
44 }
55
66 getUsersFromServer ( ) {
7- return ( async ( ) => {
8- const data = await fetch ( this . url ) ;
9- return this . users = await data . json ( ) ;
10- } ) ( ) ;
7+ return fetch ( this . url )
118 }
129
13- obtainUsers ( ) {
14- this . getUsersFromServer ( ) ;
15- return this . users ;
10+ postUser ( user ) {
11+ fetch ( this . url , {
12+ method : 'POST' ,
13+ headers : {
14+ 'Content-type' : 'application/json'
15+ } ,
16+ body : JSON . stringify ( user )
17+ } )
1618 }
1719
18- postUser ( user ) {
19- const xhr = new XMLHttpRequest ( ) ;
20- xhr . open ( 'POST' , this . url , true ) ;
21- xhr . setRequestHeader ( 'Content-type' , 'application/json' ) ;
22- xhr . send ( JSON . stringify ( user ) ) ;
20+ editUser ( infoToEdit , id ) {
21+ fetch ( this . url + '/' + id , {
22+ method : 'PATCH' ,
23+ headers : {
24+ 'Content-type' : 'application/json'
25+ } ,
26+ body : JSON . stringify ( infoToEdit )
27+ } )
2328 }
2429
2530 deleteUserById ( id ) {
26- const xhr = new XMLHttpRequest ( ) ;
27- xhr . open ( 'DELETE' , `${ this . url } /${ id } ` , true ) ;
28- xhr . setRequestHeader ( 'Content-type' , 'application/json' ) ;
29- xhr . send ( ) ;
31+ fetch ( this . url + '/' + id , {
32+ method : 'DELETE'
33+ } )
3034 }
3135}
3236
You can’t perform that action at this time.
0 commit comments