Here you find the readings you have to complete before the seventh lecture.
Give feedback on step 3 of week 5 to one of your fellow students (do this by creating issues in Github).
- Fix the issues from the last week and make sure you explain how you fixed the issue in a comment (or commit message)
You are going to write a SPA (Single Page Application) that uses the Github API. Make sure that your app uses a logical pattern just like this codepen.
Just like last week:
Make a website that fetches (= to get) data asynchronously.
-
Create a new website with external js file
-
Add a button (e.g. 'click me') that when clicked
console.logs'you clicked me!' -
Create a function that fetches from The Github API. For example from this page. For help on this check this SO post
-
Display the data that you get from the Github API on your web page.
-
Now link the two together: When you click the button -> get the data from the Github API and display it on your website
Cool we are back where we left of.
- Take a look at this:
https://api.github.com/repos/HackYourFuture/CommandLine-
Make a function which takes a single argument. The function should make an XHR request to
https://api.github.com/search/repositories?q=user:HackYourFuture+[SearchTerm]where the search term will be the argument. This argument will be the input the user has given you, so make sure that when the user clicks the button you call this function with the argument. -
Make all the repositories link their own page in Github. Use the value of the key:
nameto make this work (hint: Github urls always look like this https://api.github.com/repos/HackYourFuture/[repositoryName] where [repositoryName] would be replaced by the actualnameof the repository, for exampleCommandLine). Make sure the link opens in a new tab.
- Make sure you handle user input well. That means you need to think about empty input, and input that doesn't yield any results.
So Github has this really nice documentation
:
Check these out for example
https://developer.github.com/v3/repos/commits/
-
Extend your page with an input element. This is so the user will be able to type in text.
-
For each repository, show (in the right column) who the contributers are. You will need to use the
contributors_urlfor this.
!Important
- Do not duplicate code! This is especially important for making requests since we are making multiple ones with different urls and we want to do different actions based on the call we are making. Here are some handles to get you started:
- So write a function called
makeRequestwhich accepts (at least) the following parameters:urlandcallback. - Make sure your
callbackis called when the request errors or when it sends a response (look at the documentation) - Your
callbackfunctions should accept two parameters so it can handle both errors:errandresponse. So based on your users actions (input, hovering, clicking) you want to callmakeRequestwith a differenturland supply it with a function that handles both errors (display an error message to the user for example) and responses (render it correctly, as described below).
- So write a function called
- Make your functions small and reusable (modular)! That means create separate functions to handle certain steps.
- GO WILD
Again, check out the Github API documentation to see what kind of magic stuff you can do with it.
The assignment is to implement something extra that is not in the assignment 😱 (nice and vague right?)
So for example, we have teams in our organization. You can find out who are in there and make a call to 'https://api.github.com/users/' + userInput (where userInput is a string typed into a search field by a user). You can show the users name, avatar image (not the link to the image!) and the number of public repos they have. Or you could make an API call to 'https://api.github.com/users/user/repos' to find out the public repo's they have. Or you can show how many people starred a specific repository.
Anyway, endless fun and possibilities. Need inspiration, check out the Github API documentation. Oh and please make it look nice (hint: use the stuff you learned in HTML/CSS)!
-
Use the unmeshvrije/MyFirst repository (the one you cloned) for this homework.
-
Make a branch.
-
Name it YOUR-GITHUB-NAME-dev
-
Create a file commands.txt in your branch.
-
Add bash commands that you have learnt with descriptions
-
Then git add, commit and push them in a remote branch.
**Do not merge the changes to master branch.
** Do not make any changes to master branch.
Bonus: Write a function takes this array ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'] and returns an array which only has unique values in it (so it removes the duplicate ones). Make it a 'smart' algorithm that could do it for every array (only strings/number). Try to make it as fast as possible!
How to hand in your homework:
• Create a new repository "hyf-javascript2". Also create a new folder "week6" inside this repository.
• Upload your homework files inside the week4 folder and write a description for this “commit”.
• Your hyf-javascript2/week6 should now contain the files of your homework.
• Post the link on the slack channel and in the Google Form