API requests and Intro to DataBases

Mark Pustejovsky
3 min readSep 15, 2020

In my continued learning of back end programming @AustinCodingAcademy we are starting to learn databases and how to work with MySQL. We are combining our learning with API’s with creating our own databases.

One of the items we learned with API’s is how to return an error code if a user access the system with the right credentials, but tries to push up incorrect data. For example if the user attempts to create a resource that already exists — for example, an email address that’s already registered- we would return an HTTP status code of 409.

HTTP defines these standard status codes that can be used to convey the results of a client’s request. The status codes are divided into the five categories.

  • 1xx: Informational — Communicates transfer protocol-level information.
  • 2xx: Success — Indicates that the client’s request was accepted successfully.
  • 3xx: Redirection — Indicates that the client must take some additional action in order to complete their request.
  • 4xx: Client Error — This category of error status codes points the finger at clients.
  • 5xx: Server Error — The server takes responsibility for these error status codes.

We are tying everything we learn to our previous work with CSS and HTML. One of the questions we were asked this week was: “Consider a responsive site design that requires a full-width image in all responsive states. What would be the correct way to code this to ensure the page loads the smallest image required to fill the space?” In CSS to make your site responsive you do media queries and make elements of a size that will allow you to scale to 100% of the element width, once you set the element widths to appropriate sizes based on the the query.

Since we are learning front and back end development @AustinCodingAcademy we are developing using JavaScript. JavaScript was developed for webpages and therefore has some limitations with back coding. However node.js was created that allows JavaScript to be used on back end applications. When using node you must use a package manager to help load, create, and manage other libraries. The most common is NPM (short for Node Package Manger). However Yarn is another manager that can be used. Yarn which is fairly young has more stars compared to NPM as at the time of this writing. These two packages are now well aware of themselves, with Yarn being able to be installed using NPM. Yarn, on the other hand, can install packages from the package-lock.

When writing Node.js applications, ending up with hundreds or even thousands of dependencies can easily happen. For example, if you depend on Express, you depend on 27 other modules directly, and of course on those dependencies’ as well, so manually checking all of them is not an option!

The only option is to automate the update / security audit of your dependencies. For that there are free and paid options:

  • npm outdated
  • Trace by RisingStack
  • NSP
  • GreenKeeper
  • Snyk

This week we started learning how to make SQL queries. Learning the syntax is always step one. It is like anything else in programming. It is logical, but you must learn the proper syntax. For example: A CHAR field is a fixed length, and VARCHAR is a variable length field. This means that the storage requirements are different — a CHAR always takes the same amount of space regardless of what you store, whereas the storage requirements for a VARCHAR vary depending on the specific string stored.

Another questions asked this week was: “How else can the JavaScript code below be written using Node.Js to produce the same output?”

This can be done with a promise using async code as shown below.

Till next week, be safe.

--

--

Mark Pustejovsky

Subject matter expert in P&C and electrical testing. Adding full stack development to resume to bring technology to my next employer.