Skip to main content

Posts

Showing posts from March, 2019

Backend Developer & Development [ Part 2 ]

Incoming Requests In incoming requests, you must know about HTTP verb / method, queries, params, headers, body and flows.  For HTTP verb / method, there's are many but i only introduce most common one. All of the method have their own usage like GET           -  For client GET data from server-side POST         -  For client POST data at body to server-side for creation or other requests that used post body. PUT            - For client replace specific data with body given. PATCH       - For client update partial data with body given. DELETE    - For client delete specific data from server-side. For queries, params, headers and body, they like a message that from client. 4 of them will receive on different places. Queries  - Can found at behind of the URL. Look like  ?value=abc . Params   - Defined by backend deve...

Async / Await vs Promises

## Node.JS In node.js, asynchronous operation able to done by two ways. They are async/await codeblock or promises. What different between them? ### Promises In promises, some of them call it `callback hell` because of the syntax keep repeating callback like and until the end of the async operation. Here come with an example. ```js samplePromise: () => { var promise = new Promise((resolve, reject) => { try { // async codeblock resolve(result); } catch (e) { reject(e); } }); promise.then( (result) => { // result is returning and async operation run complete. }, (rejected) => { // rejected something wrong when running async operation } ).catch( (error) => { // unhandled error occurs when running async opeartion } ); } ``` With this example, you able see that promise code block is quite long when running an async operation, try to think what if more complex async operation required to run, like you need to get data fr...