Welcome agent! You have made it this far so we know we can trust you. BitProject is working in an undercover operation, and we need a new way to communicate.
✅ Tasks:
[ ] Run git pull and create a new branch called morse
[ ] 1: Install the morse-code-converter package
[ ] 2: Code an HTTP trigger function with morse-code-converter that takes in English as a parameter and outputs it in Morse Code
[ ] 🚀 Place the function URL of your new Morse Code HTTP Trigger as a repository secret named MORSE_ENDPOINT and commit your function's code to a file named Morse/index.js to the morse branch
[ ] 🚀 Create a pull request that merges morse to main, but do not merge it
:exclamation: Do not merge the branch!!
1: Installing Packages
Create a new HTTP trigger function in your Azure portal along with the Function App. Navigate to your Function App. This is not the function code, but the actual app service resource.
We will be using the morse-code-converter npm package.
:question: Why do we need these "packages" and what are they?
Packages are awesome! They're chunks of publicly available code that someone else has written to help make coding easier for everyone else. These packages reusable code that increases functionality in your code.
Before the Azure Function can run the code we will write, we have to install all the necessary package dependencies. These packages contain **code that we will "depend on" in the application**; we have to install them in the console using `npm install`.
[What is a package?](https://www.w3schools.com/nodejs/nodejs_npm.asp)
[What is the morse-code-converter package?](https://www.npmjs.com/package/morse-code-converter)
:question: How do I install the package?
In the left tab, scroll down to Console:
![console](https://user-images.githubusercontent.com/52464195/93178238-cf5c4e00-f6e8-11ea-90ab-c42f746cf04e.png)
Enter these commands in order:
```sh
npm init -y
npm install morse-code-converter
```
:exclamation: Woah! What just happened when the package was installed?
The first command created a **package.json** file to store your dependencies and essentially keeps track of what packages your application needs. You can find this file by going into the left menu and clicking on "App Files".
The next one actually installs the necessary packages with code, `morse-code-converter`.
*Note: If you get red text like `WARN`, you can ignore it.*
:books: Reminder: don't forget to import your package! const morse = require("morse-code-converter");
:bulb: Make sure your parameter is named plaintext
2: Using morse-code-converter
:question: How do I receive the English as a parameter?
[Query parameters](https://rapidapi.com/blog/api-glossary/parameters/query/) can be accessed from the `req` object in the input of the `module.exports` function.
> :bulb: Since ours is named `plaintext`, we can access it with `req.query.plaintext`.
**How would I send the English?**
[place your function url here]&plaintext=[insert the English]
:question: How do I use the Morse Code package?
**Tip**: Try reading the [documentation](https://www.npmjs.com/package/morse-code-converter) first.
```js
const morse = require("morse-code-converter");
const code = morse.textToMorse('Hey how are you?'); // .... . -.-- .... --- .-- .- .-. . -.-- --- ..- ..-..
const text = morse.morseToText(code); // HEY HOW ARE YOU?
```
:bulb: Be sure to return the code in the body of the response!
:question: Um. Body?
**Tip**: `context.res` is the object you use to return a response to the user.
```js
context.res = {
body: [insert your encoded English here]
};
```
:exclamation: Don't forget to git pull before making any changes to your local repo!!
Remember: we test your Morse Code function everytime you commit!
Week 1 Step 8 ⬤⬤⬤⬤⬤⬤⬤⬤◯ | 🕐 Estimated completion: 5-15 minutes
[TOP SECRET] Morse Code Converter
✅ Tasks:
git pull
and create a new branch calledmorse
morse-code-converter
packagemorse-code-converter
that takes in English as a parameter and outputs it in Morse CodeMORSE_ENDPOINT
and commit your function's code to a file namedMorse/index.js
to themorse
branchmorse
tomain
, but do not merge it1: Installing Packages
Create a new HTTP trigger function in your Azure portal along with the Function App. Navigate to your Function App. This is not the function code, but the actual app service resource.
We will be using the
morse-code-converter
npm package.:question: Why do we need these "packages" and what are they?
Packages are awesome! They're chunks of publicly available code that someone else has written to help make coding easier for everyone else. These packages reusable code that increases functionality in your code. Before the Azure Function can run the code we will write, we have to install all the necessary package dependencies. These packages contain **code that we will "depend on" in the application**; we have to install them in the console using `npm install`. [What is a package?](https://www.w3schools.com/nodejs/nodejs_npm.asp) [What is the morse-code-converter package?](https://www.npmjs.com/package/morse-code-converter):question: How do I install the package?
In the left tab, scroll down to Console: ![console](https://user-images.githubusercontent.com/52464195/93178238-cf5c4e00-f6e8-11ea-90ab-c42f746cf04e.png) Enter these commands in order: ```sh npm init -y npm install morse-code-converter ```:exclamation: Woah! What just happened when the package was installed?
The first command created a **package.json** file to store your dependencies and essentially keeps track of what packages your application needs. You can find this file by going into the left menu and clicking on "App Files". The next one actually installs the necessary packages with code, `morse-code-converter`. *Note: If you get red text like `WARN`, you can ignore it.*2: Using morse-code-converter
:question: How do I receive the English as a parameter?
[Query parameters](https://rapidapi.com/blog/api-glossary/parameters/query/) can be accessed from the `req` object in the input of the `module.exports` function. > :bulb: Since ours is named `plaintext`, we can access it with `req.query.plaintext`. **How would I send the English?** [place your function url here]&plaintext=[insert the English]:question: How do I use the Morse Code package?
**Tip**: Try reading the [documentation](https://www.npmjs.com/package/morse-code-converter) first. ```js const morse = require("morse-code-converter"); const code = morse.textToMorse('Hey how are you?'); // .... . -.-- .... --- .-- .- .-. . -.-- --- ..- ..-.. const text = morse.morseToText(code); // HEY HOW ARE YOU? ```:question: Um. Body?
**Tip**: `context.res` is the object you use to return a response to the user. ```js context.res = { body: [insert your encoded English here] }; ```:exclamation: Don't forget to
git pull
before making any changes to your local repo!!Remember: we test your Morse Code function everytime you commit!