@@ -3473,77 +3473,6 @@ const httpPost = async (url, data, cb, err = console.error) => {
34733473}
34743474
34753475
3476- // --- / --- / --- / --- //
3477- /**
3478- * REST-обертка для `fetch`
3479- */
3480- const SERVER_URL = ' http://localhost:5000/todos'
3481-
3482- const POST = ' POST'
3483- const PUT = ' PUT'
3484- const DELETE = ' DELETE'
3485-
3486- const client = async (method , payload , endpoint = SERVER_URL ) => {
3487- let config = {}
3488-
3489- if (method) {
3490- config = {
3491- method,
3492- headers: {
3493- ' Content-Type' : ' application/json'
3494- }
3495- }
3496-
3497- if (method === POST || method === PUT ) {
3498- config .body = JSON .stringify (payload .body )
3499- }
3500-
3501- if (method === DELETE || method === PUT ) {
3502- endpoint = ` ${ endpoint} /${ payload .id } `
3503- }
3504- }
3505-
3506- try {
3507- const response = await fetch (endpoint, config)
3508- if (response .ok ) {
3509- let message
3510-
3511- switch (method) {
3512- case POST : {
3513- message = ' Data has been added'
3514- break
3515- }
3516- case DELETE : {
3517- message = ' Data has been removed'
3518- break
3519- }
3520- case PUT : {
3521- message = ' Data has been updated'
3522- break
3523- }
3524- default : {
3525- message = ' Data has been received'
3526- }
3527- }
3528-
3529- console .log (message)
3530-
3531- const result = await response .json ()
3532- return result
3533- }
3534- throw new Error (response .statusText )
3535- } catch (err) {
3536- console .error (err .message || err)
3537- }
3538- }
3539-
3540- client .post = (payload , endpoint ) => client (POST , payload, endpoint)
3541-
3542- client .put = (payload , endpoint ) => client (PUT , payload, endpoint)
3543-
3544- client .delete = (payload , endpoint ) => client (DELETE , payload, endpoint)
3545-
3546-
35473476// --- / --- / --- / --- //
35483477/**
35493478 * Работа с цветом
0 commit comments