shreythecray / serverless-demo

2 stars 0 forks source link

Getting Started with Serverless #1

Closed ghost closed 3 years ago

ghost commented 3 years ago

Week 1 Step 1 ⬤◯◯◯◯◯◯◯◯ | 🕐 Estimated completion: 5-20 minutes

GitHub

This week, you will be going through steps to set up tools needed to be successful in this camp. If you are already familiar with some, feel free to skip to the end and complete the task to move on.

✅ Tasks:

What is GitHub?

GitHub is a industry-standard platform allows developers to save and collaborate on code. You can use GitHub to manage your files, changes in your project, version control (the ability to revert back to previous versions of your code as well as versions developed by other programmers), and more.

Check out "The Github Flow" for more information on issues, pull requests, committing, and branches!

If you want to learn more about what it is and how to use it, try taking this GitHub Learning Lab Course. After finishing it, you will have a strong understanding of all the features GitHub has to offer.

✍️Vocabulary #### Repositories Repositories (or repos) are essentially **folders where you can store files of code.** The repo of our camp was duplicated into your account when you clicked "Create Template" so that you can commit changes and complete each lesson. #### Issues For our camp, each week is placed inside an issue. Only when you complete the week (committing the necessary code and commenting), will the issue close and you can move on to the next issue. Don’t worry – committing changes is easier than it sounds. *On usual repositories in the contributing world issues are tasks or bugs that need to be completed or fixed.* #### Fork If you want to contribute to someone else's code, you would "fork" it. This creates a copy of the code under your account that you can make changes to. Create a fork when you **want to make changes to someone else's code and contribute to it.** #### Branch Creating a **branch** on a repository is like forking a repository. You would do this when you **want to make changes to your code without harming a working version.** #### Pull Request Once you make changes on **a forked repository or another branch,** you might need to bring the changes into the "main" repository. This allows YOUR changes to be visible in the main project! *You are basically asking for permission to "merge" your changes." **This allows you to:** * Collaborate on code * Make comments * Review the contributions made #### Command Line Interface A Command Line Interface (CLI) is your computer's visual application for accessing its operating system. There are different types of CLIs for different operating systems, such as Terminal for MacOs and PowerShell for Windows. If you have Windows, make sure to also install [Git Bash](https://git-scm.com/downloads) for a better tool. In upcoming issues, we will refer to your CLI as your Terminal or Command Line, but remember that they mean the same thing!

Key functions you should be familiar with after this task include:

ghost commented 3 years ago

Week 1 Step 2 ⬤⬤◯◯◯◯◯◯◯ | 🕐 Estimated completion: 5-20 minutes

Say "Hello" to VS Code

✅ Tasks:

:bulb: Tip: When we tell you to name a file called directory/thefile.js, the first part before the / is a directory (otherwise known as a folder).

🚧 Test your Work

If you run node helloworld.js in the terminal, the output should be Hello World

Note: From now on, you will never need to close an issue. The Counselor will do that for you, create new issues, and new comments for further instructions!

:x: My code failed, what do I do?

No worries, check this out to help resolve the issue.

:bulb: TIP: If you want to re-run a check without comitting something else, check this out.

1: The IDE - Visual Studio Code

An IDE is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools, and a debugger. Although there are hundreds of IDEs to choose from, we are going to use Visual Studio Code due to its popularity and integration with Azure (via extensions and libraries).

:computer: How to set up your VS Code Environment
[Download VS Code](https://code.visualstudio.com/download) for your operating system and check out this tutorial before getting started. Inside VS Code, download the following extensions: - Azure Tools (includes Azure Account, Azure App Service, Azure Functions) - Live Server All of the Azure extensions allow you to work on your Azure Function App in VS Code instead of working directly through the Microsoft portal. Live Server is a quick and temporary testing server, and you can use it to test HTML pages. To launch, right click on your html file and press "Open with Live Server" or click "Go Live" in the bottom right corner: Screen Shot 2021-01-10 at 1 53 20 PM Screen Shot 2021-01-10 at 1 53 40 PM

Note: Dark Theme is our personal favorite, but feel free to choose whichever theme you like best. Go to this site to view your options!

2: GitHub with VS Code

Check out this awesome documentation about how to set up Git on your local computer

:exclamation: How do I use GitHub on VS Code? 1. Once you have complete the steps in the documentation, clone this repo on your computer 2. Use the following commands to work with branches in the terminal: - Check which branch you're in: `git branch` - Create a new branch and change into it: `git checkout --b name-of-branch` - Change branch: `git checkout name-of-branch` 3. Afterwards, follow [this tutorial](https://code.visualstudio.com/docs/editor/github) by VS Code on connecting to GitHub straight from the app!

:exclamation: Don't forget to git pull before making any changes to your local repo!!

3: Writing and Exporting a Javascript function

JavaScript enables the ability to export functions in a program so that you can access them in other parts of the program via the import statement. In this case, we want to export your programs in order for CounselorBot to check your code.

:question: What are JavaScript and Node?
Javascript is the language of the internet! It is a powerful tool for creating complex web apps. However, JavaScript can be used for building the client for applications, and sometimes requires a way to access this client, which is also known as the server-side. Node.js is the solution to this problem, and allows you to write and run code not linked to a website locally. :exclamation: Make sure you have Node.js and npm installed before moving forwards: https://www.npmjs.com/get-npm * Check if node is installed: run `node -v` in your terminal * Check if npm is installed: run `npm -v` in your terminal If you would like to read more, refer to [this article](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/What_is_JavaScript) on JavaScript and [this article](https://www.tutorialspoint.com/nodejs/nodejs_introduction.htm) on Node.

:question: How do I export a function?
Let's say your function name is `hello`. To export it, add this line of code at the very bottom of your file outside of your function: `module.exports = hello`. Example: ```js function hello() { // your code } module.exports = hello ``` When you commit the file, we will try to run the function by importing it and compare it's output to the expected output like so: ```js let hello = require('../../week1/helloworld.js') let output = hello() ``` ### How does this apply to code in the real world? Just like you can import code from modules other people have written, you can also **import functions you wrote from *other files* to reuse them.** In function oriented programming, you use functions over and over again to save code. If you want to use the function `hello()` in another file, you would need to import it.

:question: Can I have more detailed steps?
1. Create a new file 2. Name the file helloworld.js 3. Write your code 4. If you have node installed on your computer, open terminal on VS Code and type 'node helloworld.js' 5. If you have not installed node on your computer, you will need to do that first: https://nodejs.org/en/download/ 6. Tip: to test your function, call it in your code. 7. Create a new branch named `week1` and commit your `helloworld.js` file in the root directory.

:bulb: Try to not use the web editor! Commit from your command line.

🚀 Commiting to a repository using a command line?

Start out by downloading Git. Then, open your command line.

The Commands

Navigate to the directory in your command line where you want to keep your repository.

Tip: Use cd ./your-directory to change directories, pwd to find out where you are, and ls to list files & directories. More information is here.

Cloning your repository Click on "Code" on your repo's page and find your repo's HTTP link:
Use the `git clone` command **and replace the url** to get your repository's files onto your local computer: ``` git clone https://github.com/example/example.git ``` Now is the time to make your changes to your code!


Committing and pushing code First, "stage" your changes. You will be specifying what files you want to commit the changes of. Stage `helloworld.js` changes only: ``` git add helloworld.js ``` Stage ALL your changes to the repository: ``` git add * ``` Next, let's commit the code. Usually, your commits will be a group of changes that make sense together. *Add a description!* ``` git commit -m "insert your description" ``` Save your commits to the repository on Github! ``` git push ``` **For more information, refer to [this link](https://docs.github.com/en/github/managing-files-in-a-repository/adding-a-file-to-a-repository-using-the-command-line)**


Congrats! Your changes should now be visible on Github

:exclamation: Don't forget to git pull before making any changes to your local repo!! This gets any changes that were made by the bot.

ghost commented 3 years ago

Week 1 Step 3 ⬤⬤⬤◯◯◯◯◯◯ | 🕐 Estimated completion: 10-15 minutes

Getting Cat Pics with Postman 🐱

In this step, you will be using Postman to test the CataaS API by sending a GET request.

✅ Tasks:

1. Exploring the CataaS API

CATAAS is a RESTful API that exclusively delivers images of cats. The main feature is that we can change the properties of images, add text, truncate the image, add a filter and more. It's not an API with many real-world applications, but it's perfect for learning.

Interested in playing around with the API? Documentation is here.

How does the cloud work? ["The cloud"](https://www.cloudflare.com/learning/cloud/what-is-the-cloud/) refers to servers that are accessed over the Internet, and the software and databases that run on those servers. Cloud servers are located in data centers all over the world. By using cloud computing, users and companies don't have to manage physical servers themselves or run software applications on their own machines.
What are HTTP Requests? A [server](https://www.infotech.co.uk/blog/it-infrastructure-what-does-a-server-actually-do) is a computer that provides (serves) data to other computers, called clients. Clients connect to servers through the internet. Clients communicate with servers with through `HTTP requests`. For example, when you are on your favorite browser and look up YouTube.com, you are making an HTTP "get" request to the server to load the contents from YouTube.com.
:exclamation:What are some examples of request types??
Below are some of the most common HTTP requests. Read through each one, and try to get familiar with their functions! **Get Request**: gets data from a server (hence the name). The data we want is specified using a URL we call a Request URL. In this case, you will use a Get Request URL from the Catass API to receive a cat picture. **Post Request**: used to send data to a server, to create or update a resource. The information submitted to the server is archived in the request body of the HTTP request. This is often used to send user-generated data to a server. An example could be uploading a picture to a Post URL. **Put Request**: similar to a Post Request, but a put request will always have the same result every time you use one, whereas a post request might not. We call this property "idempotency." **Delete Request**: used to delete resources indicated by the URL and will remove the targeted resources.
What are APIs, and what makes one "RESTful?" An API is a piece of software that lets two other pieces of software talk to each other! Imagine you're driving a car - the wheel and pedals would be like APIs between you and the car, since they allow you to controll the car easily. Most of the time, an API will be used to connect an app to an external service. For example, the Twitter API could allow a user to automatically receive updates on tweets concerning a particular topic or event. Any API that follows these 5 rules is, by definition, RESTful. **You don't need to worry about the 5 rules**, but if you're curious... 1. Internally, the API should keep the things the user does and the things the server does separate. 2. The server shouldn't ever need to store the user's data to function. 3. All output data from the API should mark itself as either "cacheable" or "non-cacheable" (cacheable data can be stored and reused later by the user, while non-cacheable data should be discarded and recomputed by the API every time). 4. The user shouldn't be able to tell whether or not they're communicating with the API's server, or an intermediary server. 5. The interface of the API should conform to a few agreed-upon conventions (that we won't be going over here).

2. Sending Requests with Postman

In this step, we'll be using a software called Postman to test an API. Postman is a debugging tool for RESTful APIs, which allows you to test both pre-existing, community made APIs, or your own self-made APIs, without having to write any HTML test code!

https://media.giphy.com/media/Kxs6TTeI4siCJKKRMC/giphy.gif

You can sign up for Postman here.

:question: How do we build requests? The [Postman documentation](https://learning.postman.com/docs/sending-requests/requests/) covers: * Creating requests * Adding request detail * Setting request URLs * Selecting request methods * Sending parameters * Sending body data * Authenticating requests * Configuring request headers

Open up Postman and try it out yourself:

:question: How do I specify the API Endpoint?
Enter https://cataas.com/cat/cute/says/Serverless, which is the API endpoint, into the text box next to GET ![image](https://user-images.githubusercontent.com/69332964/98034882-ad787100-1de5-11eb-83fd-9cb73f78beae.png)

:question: How do I set the parameters?
Click on "Params" and enter `color` into Key and the color you want (eg. blue) into Value. Enter `size` into the next Key row and a number (eg. 50) into Value. > **Note on parameters:** > * the `size` parameter refers to the font size of your caption. It has a limit at around 1,200. > * Colors are pretty hit or miss; since the Cat API is on the web, but it generally adheres to HTML color names. Expect values such as "blue, green, yellow" to work. > * The API can take very large words as input for the caption, however only **34** characters can be seen on the picture at one time .

Click Send to get your cat picture

shreythecray commented 3 years ago

response

ghost commented 3 years ago

⚡️ You're ready for Serverless!

Move on to the next issue.

moveon