Category Archives: Week 10

How to Design a REST API

When designing an API it is extremely important to get it right the first time. API calls are the backbone of you application, and without well designed endpoints your frontend will not be able to communicate with your backend effectively, if at all. If you do not design your API with forward thinking in mind, you may end up redesigning many of your endpoints and a good portion of your application as well. The good news is that API design is usually left to experienced developers; the bad news is that experienced developers still mess up from time to time.

Since designing a good API is so important, there are many standard practices which will help you with your design process. “REST API Best Practices – REST Endpoint Design Examples” is an article written by Kolade Chris which outlines nine best practices that you should keep in mind whenever you are designing an API.

To begin with the simple practices, it is important to use JSON format for sending and receiving data. Firstly this is a good practice because it is industry standard, but more importantly it is designed to be used with many of the most common frontend languages, such as JavaScript, PHP, and Python.

Practices two and three are similar since they both relate to naming convention; use nouns instead of verbs as endpoints, and name your collections plural. The reason you should use nouns as endpoints is because the verb part is contained in your HTTP request such as POST or GET, so you can do GET /items. The reason you should use plural collection names is to indicate that it is in fact a collection and not a single item.

The fourth practices Chris mentions is to follow industry standard status codes. This is very important, but also not difficult to do; simply look up standard status codes and follow those.

Practices five and six are also similar to each other; they both relate to narrowing your search. When designing an API, you should use nesting to indicate how things relate to each other, and you should also use filtering, sorting, and pagination to narrow down a request which returns multiple values. For example, if you wanted to find a specific blog post by title you could design your endpoint like this: https://blog-website.com/users/userId/posts?title=query. This indicates that the post exists within the user endpoint, and also queries based on title.

An easy but important practice is to use SSL with your endpoints. When using SSL you will have https// instead of http//. The increased security is definitely worth the expense you might need to pay.

The final two practices are the most important: use semantic versioning and provide adequate documentation. It is important to use versioning when designing an API so that users are not forced to use the most updated version, and it is important to provide documentation so that users know how to actually use the API.

Following these practices does not guarantee that your API will be designed well, but it does ensure that you won’t have basic problems with it.

From the blog CS@Worcester – Ryan Blog by rtrembley and used with permission of the author. All other rights reserved by the author.

Web Development/Front end vs Back end

What is a Web Development?

Web development, at its most basic, is developing a website for the internet. Web development generally refers to the more non-design aspect of a website, which includes using programming, markup, and scripting languages to create features and functionality. Developers focus on the technical part of building a website, such as constructing the layout, programming, and integrating applications and graphics.

What types of Web Development are there?

The front end, back end, and full stack web development are three separate career paths that can sometimes feel muddied in the technology space. Front end developers help build what users interact with and see, back end developers are focused on data, modeling, and the back end of a website. A full stack developer does some or all of the above.

What is a Front End Developer?

Front end development is the part of web development that codes and creates front-end elements of a website, which are features that are directly viewable and accessible by the end-user or client. A front end developer is responsible for everything we see and works to enhance the user experience to ensure it is seamless.

What are some skills required for Front End Developers?

  • A good gasp of front end programming languages
  • The ability to create a responsive design
  • A knowledge of testing and debugging
  • An understanding of front end developmemt tools and features like automation, content management systems, version control systems, and frameworks.

What is a Back End Developer?

Back end development is aptly named for web development that occurs at the back end of programs. Back end developers write codes to help a database and application communicate. Essentially, a back end developer handles what we don’t see; they are in charge of the back end of a website, which includes servers, databases, and applications.

What are some skills required for Back End Developers?

  • Database management
  • Framework utilization
  • Programming
  • Knowledge of accessibility and security compliance

Differences between front end and back end.

Front end and back-end development are quite different from each other, but still, they are two aspects of the same situation. The front end is what users see and interact with and the back end is how everything works. The visual aspects of the website that can be seen and experienced by users are the front end. On the other hand, everything that happens in the background can be attributed to the back end.

Languages used for the front end are HTML, CSS, JavaScript while those used for the back end include Java, Ruby, Python, .Net.

I chose this topic because learning about front end and back end development is really important. As a computer science major with a double concentration in software development and data analytics, this is important information I need to know in order to become a good programmer.

Front End vs Back End Development: What Is the Difference? (switchup.org)

Frontend vs Backend – GeeksforGeeks

From the blog CS@Worcester – Gracia's Blog (Computer Science Major) by gkitenge and used with permission of the author. All other rights reserved by the author.

NoSQL

During this semester we have started to use MongoDB. While I did get some general explanations of MongoDB in class, I felt like I needed to get a better grasping of how MongoDB works as a database and how I can better use it. Since MongoDB is a NoSQL styled database and my general understanding of databases comes only from using relational databases, I felt like an article helping to summarize and clarify NoSQL would be advantageous.

https://dev.to/lmolivera/everything-you-need-to-know-about-nosql-databases-3o3h

This article goes into great detail not only the advantages or features of NoSQL but the terminology used alongside with it. It has descriptions of multiple types, how they differ and what they are used for and including some helpful guides around designing these different types of databases.

More specifically my focus is on the type of NoSQL database that MongoDB is which is a document based database.

As the article describes, a document type database stores it’s data inside of a “document” that could contain varied types of data. Even to the point of storing documents nested inside of other documents. Which highlights the advantage of this type of database which is scalability. Being able to store nearly anything inside the database and not needing to force it’s formatting is a great feature. I’m trying to think of a scenario needed for nesting your entire database inside as an object containing your entire database. I don’t seem to be able to think of one in specific, but the concept is interesting to me and maybe it’ll be useful later.

This article also briefly goes into describing how JSON formatted NoSQL databases are structured. This was good to see as this is exactly what I have been using in class as well as in the most recent homework assignment.

It also gave a link to a list of databases who have used Document based NoSQL databases and was interested to see eBay listed their and specifically using the same database MongoDB as we are using in class.

https://www.edureka.co/blog/real-world-use-cases-of-mongodb/

Near the end of the article it begins to describe the CAP Theorem. The theorem as I learned from this article to be a general issue around picking which attribute we focus on for the service. Is it frequently consistent with reads/writes? Does every request have the most recent changes? Does it still perform it’s functions when some of the machines are currently not connected? This concept details that you must pick only two and generally partition tolerance is chosen first as one of the two. The reasoning being that as a service being able to provide it regardless of a particular aspect of the database going down you still want to be able to provide a service.

Overall this article gave me some good general insight on what a NoSQL database specifically is and how it is generally used and will help me in class when referring to the database we have been using MongoDB.

From the blog CS@Worcester – A Boolean Not An Or by Julion DeVincentis and used with permission of the author. All other rights reserved by the author.

The Basic Docker Compose File Structure

In last week’s blog, I covered docker compose files and their significance. For today’s blog, I would like to go in depth on docker-files to explain how they are structured. To give a quick review of what Docker Compose is. Docker Compose is a tool that allows developers to create and run multi-container docker applications. Once again, I am referring to The Definitive Guide to Docker compose, posted by Gabriel Tanner. He does a good job of breaking down the structure of a docker-compose.yml file.

Docker Compose File Structure

By using a docker file, you can list the containers you want and all of the specifications as you would in a docker run command. As explained in last weeks blog, almost every docker-compose file should include the following:

  • The version of the compose file
  • The services which will be built
  • All used volumes
  • The networks which connect the different services

Docker files are structured upon indentation. Consider the idea of levels of abstraction.

On the top levels are the version, services, and volumes tag. The next level down is where the containers are listed, then parameter tags such as image, volumes, and ports. And finally on the lowest level, the respective rules for each parameter.

Here is a simple docker-compose.yml file:

Let’s take a look at each tag individually.

Version:

The version tag is used to specify the version of our compose file, based on the Docker engine we are using. For example, if we are using Docker engine release 19.03 or later:

Services:

The service tag acts as a parent tag, as all of the containers are listed underneath it.

Base Image/Build:

The image tag is where you would define the base image of each container. You can define a build using preexisting images available on DockerHub. In this case, we are defining a web1 container using the nginx:mainline image. 

You can even define the base image by pointing to a custom Dockerfile:

https://gabrieltanner.org/blog/docker-compose

Volumes:

The volumes tag allows you to designate a directory where the persisting data of a container is managed. Here is an example of a normal volume being specified.

https://gabrieltanner.org/blog/docker-compose

Another way of defining a volume is through path mapping, linking a directory on the host machine to a container destination separated by a : operator.

Ports:

Specifying a port allows you to expose your host machine to the container that is running. In this case, we are defining port 10000 for the host port and we want to expose it to port 80.

Those are all of the main components that you need to structure a Docker Compose file. In this blog post, I simply covered the basic tags and structure. Compose files allow you to manage multiple containers and specify properties to a finer detail. There are tags that I haven’t covered such as dependencies, commands, and environment that Gabriel explains really well. 

From the blog CS@Worcester – Null Pointer by vrotimmy and used with permission of the author. All other rights reserved by the author.

CS-343 Post #5

After doing more work with activities 13 and 15 and working on homework 4, I wanted to read more about how to use the http methods with REST API calls because I was having some trouble understanding how to implement them in the homework at first and wanted to get a better grasp on how they work to set up my endpoints and paths.

I have decent understanding of each of the methods and how they correlate with the paths and endpoints we have been working with so far. The main source I used for reading more about the methods was the REST API tutorial about http methods. It goes over each of the methods and gives a summary at the end which is a table. It also gives a brief glossary over some terms used and references to other sources. It gave good explanations for each method and was divided in evenly sized sections.

The main five methods used that we are familiar with are GET, PUT, POST, DELETE, and PATCH. GET is used to find and return an item or object based on the parameters we choose, like a name or ID. POST creates an object and posts it to the data. PUT updates and replaces data for an object. DELETE removes/deletes an item/object. PATCH is used for minor/partial updates. We have not used PATCH in our activities yet, but it did show up as a method in an example given for activity 12 for how http methods work with urls.

Going more into the methods, GET methods are considered safe methods because they do not make any changes to the data, and they are also idempotent because they are expected to allow multiple similar requests with the same results. The other methods all change the code or data in some way, so they are not considered safe. DELETE is the other idempotent method because the result of each DELETE is a removed object. PUTs and PATCHs seem the same because they both are used to make changes to existing data, but they differ how much they update. PATCHs are for smaller and partial updates, while PUTs are for bigger updates and usually involve replacing existing data.

After this reading and doing more work with REST API, I have a better idea on how to implement them in code and continue with the activities and homework.

https://restfulapi.net/http-methods/

From the blog Jeffery Neal's Blog by jneal44 and used with permission of the author. All other rights reserved by the author.

Concurrency

https://www.vogella.com/tutorials/JavaConcurrency/article.html

This article discusses the use of Concurrency in Java. As defined in the article Concurrency is “the ability to run several programs or parts of a program in parallel”. Concurrency is meant to cut down on time and make a program or programs more effective and easier to use together. The article describes how Java uses several threads to “parallel process” or behave asynchronously which ultimately makes the application run faster and smoother. Concurrency is all about the performance gain in the application, this gain can be calculated using “Amdahls Law” which tells you the maximum performance gain.

According to the article a Java program runs its processes in one thread (by default) through javas “Thread Code” which is also capable of allowing multiple threads through the Thread class. Through threads you use the synchronize keyword in order to define which methods or code should be executed by one single thread. The synchronized keyword provides specific sections of code with a “lock” and any code protected by this lock will be executed by one thread instead of multiple. The memory of threads communicates with the memory of the application through the “java memory model” which also allows the thread memory to refresh itself with the main memory.

I chose this article as it goes into depth about the subject of Concurrency and helps students like myself understand what exactly concurrency is and what the purpose or use of concurrency is. Concurrency is a complex subject as it involves the thread class which isnt commonly used by beginners in java and it involves new keywords not previously learned. The article goes into detail about threads and what exactly they do/why they are important and it also tells you the exact purpose of concurrency which is program efficiency i.e. speed, correctness, etc.

I actually learned quite a bit from this article. I already knew the general idea/concept of concurrency and what it is but as far as the more in depth information which was provided like threads, synchronize and volatile I never knew exactly what each part was and what they each entailed. This article was organized very well and provides the reader with the necessary information in order to learn about and work with concurrency in their own code. Overall the article was very helpful and I would recommend it to other students as it explains the subject very well.

From the blog CS@Worcester – Dylan Brown Computer Science by dylanbrowncs and used with permission of the author. All other rights reserved by the author.

MongoDB

What is it?

MongoDB is an open-source database with a document-oriented data format and a non-structured query language. MongoDB Atlas is a globally accessible cloud database solution for modern applications. This best-in-class automation and well-established procedures enable completely managed MongoDB deployments on AWS, Google Cloud, and Azure. It also guarantees availability, scalability, and adherence to the most strict data security and privacy standards. MongoDB Cloud is a unified data platform that comprises a global cloud database, search, data lake, mobile, and application services, as well as a global cloud database.

Is MongoDB a SQL?

No. It is not. It is one of the most powerful NoSQL databases and systems available today. Because it is a NoSQL tool, it does not employ the traditional rows and columns associated with relational database administration. It is a collection-based and document-based architecture. A collection of key-value pairs is the basic unit of data in this database. It provides for varied fields and formats in documents. This database stores documents in the BSON format, which is a binary version of JSON.

Originated/Creation

Dwight Merriman, Eliot Horowitz, and Kevin Ryan found MongoDB in 2007. They decided to create a database to solve the difficulties of scalability and agility that they were seeing at DoubleClick. That’s when MongoDB came into existence. In 2009, the company made the move to open-source development, with commercial support and extra services offered. In 2013, the company’s name was changed to MongoDB Inc. from 10gen. It went public on NASDAQ as MDB on October 20, 2017, with an initial public offering (IPO) price of $24 per share. On October 30, 2019, it announced cooperation with Alibaba Cloud to deliver a MongoDB-as-a-Service solution to its clients. BABA’s managed services are available from any of the company’s data centers across the world.

Advantages of using MongoDB

MongoDB may be operated across globally scattered data centers and cloud regions, offering unprecedented levels of availability and scalability. Fast and Iterative Development: Your company’s project delivery will no longer be hampered by changing business needs. Developers can quickly design and update applications thanks to a flexible data format with changeable schema and powerful GUI and command-line tools. MongoDB’s versatile data model stores data in JSON-like documents, making data storage and combining simple. The document model is mapped to the objects in your application code, making data manipulation simple.

Why did I pick MongoDB?

I chose to study more about MongoDB after seeing a lot of MongoDB terminology in our class activities and homework assignment. I knew it was a No SQL database that used the JSON format, but I didn’t know much else. I learned about MongoDB’s history, including how it was formed, when it was created, who built it, and why it was created. I also studied how MongoDB differs from other databases like MySQL, Cassandra, and RDBMS. The advantages of using MongoDB were the most that impressed me.

Link: https://intellipaat.com/blog/what-is-mongodb/#no1

From the blog cs@worcester – Dream to Reality by tamusandesh99 and used with permission of the author. All other rights reserved by the author.

Back-end API

These weeks, I’ve been learning about APIs and back-ends. I also had the opportunity to practice with an API in my current homework. However, I am very confused about the relationship between API and back-end. I don’t understand how the API is related to the back-end, what the API and back-end are used for.

To answer those questions, I tried to search for some information about API and back-end. Back-end API development introduction, written by Cesare Ferrari, is a resource that I have found useful. The website has clear definitions of back-end and API; and their relationship is also described in detail, which helps me get better understanding of the two new terms. From the website, I know that back-end is a service that will send data to the front-end which interacts with the end users. On the other hand, API, Application Programing Interface, is a set of definitions and protocols for building and integrating application software. API can be also considered a back-end component, which is typically used by front-end applications to communicate with back-end applications. In other words, the API is used to outline all the requirements or functions that will interact with the end user. The back-end will rely on the API to create endpoints that fulfill all the requirements designed in the API. There are different types of APIs, but the REST APIs, which stands for Representational State Transfer, is one of the most popular. It communicates via HTTP requests to perform four basic functions known as CRUD. These are creating data (post), reading data (get), updating data (put), and deleting data (delete).

Moreover, the website also provides a general information of Node.js and Express to explain more how to create and use back-end applications. Node.js is used to execute a Javascript on the back-end without the browser. Express is a library or a Node.js application is used to create and send HTTP requests.

All in all, I think the website is a good resource because it’s short, concise, and provides the essential information I need. It gives me a general idea of what the back-end and API are, and how the back-end and API relate to each other. By understanding the two new definitions, I was also able to understand what I was supposed to do in each one. Based on what I read from the site and what I did with my API homework, I can envision the API as an interface class and the back-end as my concrete class that will implement all abstract methods from the interface class.

From the blog CS@Worcester – T's CSblog by tyahhhh and used with permission of the author. All other rights reserved by the author.

More on REST APIs

REST APIs have become increasingly popular over the last few years, and for good reason. REST has less of a learning curve than other API models, has a smaller footprint, and parsing of JSON is less intensive than traditional XML parsing. There are a few key standards to REST, including utilizing certain requests like GET, POST, PUT, and DELETE, for example.

When a call is made using REST API, there are a few things that go on within the call itself. First are the endpoints, which is a unique URL that is used to represent objects or groups of objects of data. Every API request has its own endpoint. In addition, there are also the methods used for the request. These include those I listed above, like GET, POST, and PUT. A header contains the information that represents the metadata associated with the REST API request. The header also indicates the format of the request and the response, and provides information about the status of the request. Lastly, the request also consists of data, which is also referred to as the body, that is usually used with the POST and PUT commands and contains the information that will be updated or created.

Another important part of REST APIs are parameters. When someone is sending a REST API request, they can use parameters to narrow or further specify their search request. These are valuable tools, since it allows you to filter the data being received in a response. Some parameter types include path, header, cookie, and the most common, query. Query parameters are located at the end of a URL path and can either be required or optional. This can be useful if, for example, you are using a base GET command to get all of the objects in the database, and you can have an optional parameter to specify which of all those objects you want, using something like ID or name, depending on your implementation.

Source

I chose the above source because it gave good additional information on REST APIs, compared to other websites I visited. This helped me further understand how REST APIs differ from other web APIs, and what helps make REST different and usually better. REST APIs definitely have their many uses, and allows ease of use with their standards of requests, using easy to understand methods like GET, POST, and PUT, to name a few.

From the blog CS@Worcester – Erockwood Blog by erockwood and used with permission of the author. All other rights reserved by the author.

Docker

Resource Link: https://www.linode.com/docs/guides/when-and-why-to-use-docker/

For this week I decided to research and write about what exactly docker is and what it’s used for in commercial applications or projects. With how much we use docker in class, I was curious as to what its other applications were and how it was used it other settings. I was curious about this because I had never heard of docker or used docker before this class, and it seems like such a useful and important piece of software. Even with just what we’ve covered so far in class, it appears to be very versatile and suitable to a variety of different applications.

This article summarizes what docker is, when and how it originated, the benefits of docker, and when and when not to use docker. I chose this article because it provides all the necessary information in a clean and concise way. While many other resources about docker were bloated and included lots of unnecessary information, this one has just the right amount of information to inform a user about what docker is, how to learn more about it, and how to get started using it. This makes it a great resource for someone new to docker, who maybe just heard about it and doesn’t know exactly what it is.

First, the article provides details about what docker is and when it was released. Docker was released in 2012, and since has become an important technology in web development. This was surprising to me because I figured I would have heard about such a big and important technology in web development, at least in one of my other classes. I figured that since I hadn’t heard of it, it must be a newer technology, but it’s already 9 years old. However, it does make sense that it would be a fast growing piece of software because of its versatility and ease of use. It makes the process of setting up and configuring a web server much simpler than it would be otherwise, and it makes monitoring those web servers easy through the docker application.

Next, the article delves into some of the benefits of docker. The benefits include reproducibility, isolation, security, docker hub, environment management, and continuous integration. Docker is reproducible in a similar way to a java application, because whereas a java application runs on a java virtual machine that is the same across all operating systems, a docker container runs in docker and is the same across all operating systems. This is very useful because it means that the container doesn’t have to be changed across different operating systems, meaning that setup time is reduced. Then, isolation is the property of a docker container where it can have instillations independent of the operating system it’s on, and independent of other docker containers. This helps to avoid conflicts between docker containers that may require different dependencies or installations. Next, with the different parts of an applications separated into different docker containers, security is increased. This is because if a single docker container is compromised, other docker containers won’t be affected. Also, different containers means that different versions of a project can be maintained independently, for example for testing. The docker hub makes it easy to find and use certain images, also leading to ease of setting up a docker container. Finally, docker can be used as a part of tools like Jenkins, meaning that when an update is made, it can automatically be saved and pushed to docker hub as an image, and put right into deployment. This cuts down on development time, and increases the ease of use by reducing the amount of work that must be done manually.

From the blog CS@Worcester – Alex's Blog by anelson42 and used with permission of the author. All other rights reserved by the author.