Skip to content

Commit

Permalink
Tweaks for session 1
Browse files Browse the repository at this point in the history
  • Loading branch information
calaldees committed Sep 24, 2023
1 parent 3c3ff63 commit 0e8a782
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 47 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ Programming Frameworks and Languages
* Cloud VSCode IDE
* GitHub CodeSpaces
* [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/calaldees/frameworks_and_languages_module?quickstart=1)
* https://codespaces.new/USERNAME/REPO?quickstart=1
* Manage: https://github.com/codespaces/
* Shutdown: `gh codespace stop`
* Issues:
* Ports need to be set to `public` manually
* Ports need to be set to `public` manually (this can't be automated and is tedious)
* [Allow for ports to be public by default #4068](https://github.com/orgs/community/discussions/4068)
* `gh codespace ports visibility 8000:public -c $CODESPACE_NAME`
* GitPod
* [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/calaldees/frameworks_and_languages_module)
* https://gitpod.io/#https://github.com/USERNAME/REPO
* Manage: https://gitpod.io/workspaces
* Shutdown: `gp stop`
* Issues:
* [GitPod: granting-additional-github-oauth-permissions](https://www.gitpod.io/docs/configure/authentication/github#granting-additional-github-oauth-permissions)
* `public_repo`, `repo` and `workflow`
* `git push` wont work until permissions are set
* [GitPod: granting-additional-github-oauth-permissions](https://www.gitpod.io/docs/configure/authentication/github#granting-additional-github-oauth-permissions)
* `public_repo`, `repo` and `workflow`
4 changes: 2 additions & 2 deletions client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ DOCKER_IMAGE:=client
build:
docker build --tag ${DOCKER_IMAGE} .

test:
docker run --rm ${DOCKER_IMAGE}
run:
docker run --rm -it --publish 8001:8001 ${DOCKER_IMAGE}
104 changes: 82 additions & 22 deletions docs/01a introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Who am I?
* 6 years - Global Radio (full stack web, android dev, lead test and internal tooling engineer)
* 6 months - Financial investment platform CI infrastructure
* 1.5 years - NHS Genome processing pipeline for cancer and rare disease analysis
* 4 years Lecturer in Education (teacher training)
* 2 years Lecturer in Computing
* 5 years Lecturer in Education (teacher training)
* 3 years Lecturer in Computing

* Side projects
* DMX Stage lighting and projector sys (with 3d stage visualiser)
Expand All @@ -38,6 +38,8 @@ TASK: (10min)
To develop the student’s understanding of the fundamental concepts of Programming Frameworks and Languages.
This module supports the Implement and Operate elements of the CDIO model.

* [module_handbook.md#employable-skills](./module_handbook.md#employable-skills)

### Intended Learning Outcomes
By the end of the module students should be able to:
1. Demonstrate an understanding of the concept of a Framework in general, a Framework used for Programming, and a Framework used for software Testing
Expand All @@ -64,20 +66,23 @@ This module will help develop an important part of your professional skill-set:
* Framework
* Inversion of control
* It calls you, rather than you call it
* Tests
* Tests that are
* Automated
* Document business requirements/spec
* Document correct flow

### How will we learn

1. Focus on a business engineering problem with real industry tools
* Hands-on each week with a range of tools
* Hands-on each week with a range of tools
2. Discussion
* Real engineers can discuss/reason about technology
* Pair programming
3. Multiple languages
* Real engineers can discuss/reason about technology
* Pair programming (you have to verbally describe your rational)
3. Multiple languages/frameworks (they are all just tools that you can learn)
* [langauge_reference.html](https://computingteachers.uk/static/langauge_reference.html)
4. Self directed (Level 6) 150 hours
* You can read + action on your own now


#### Level 6
* Level 4 - You are told what to do
Expand All @@ -87,7 +92,7 @@ This module will help develop an important part of your professional skill-set:
* My role is NOT to have all the answers
* My role is to facilitate your transition towards a skilled professional

Side Note: Employment. Popular languages? Less popular or new languages? Mark scheme 70%+
Side Note: Employment. Popular languages? Less popular or new languages? Mark scheme 50%+

#### Session Overview - Online/Campus

Expand All @@ -96,6 +101,8 @@ Task: Look on blackboard at session list
* Each week
* 09:00 - 13:00 Lab
* 14:00 - 18:00 Supervised Workshop Support
* First 3 week (vital)
* can be flexible later in the module


Starting point Quiz (15min)
Expand All @@ -107,10 +114,29 @@ How much do you as a class know already?
https://b.socrative.com/login/student/
`CALLAGHAN1818`

(Go over each question and why it was asked)



Assessment 1 - Digital Artefact - Familiarisation (1 hour)
Key Terminology (Today)
---------------
* Cloud based IDE
* Bash/linux commandline
* Makefile
* Containerisation
* Git version control (from commandline)
* GitHub Actions (CI) (to run tests - triggered by `git push`)

Today
-----
* Morning
* Overview of assignemnts and core tools
* Afternoon
* HTTP (curl and other methods)
* JSON and working with dynamic data structures
* OpenAPI spec


Assessment 1 - Digital Artefact - Familiarisation (2 hour)
------------------

### Read (10 min)
Expand All @@ -119,7 +145,7 @@ Assessment 1 - Digital Artefact - Familiarisation (1 hour)
* TASK: Look at Assignment 2 - read it - discuss


### Demo
### Demo (15 min)

* Demo working server on Cloud VSCode IDE
* https://codespaces.new/calaldees/frameworks_and_languages_module
Expand All @@ -140,14 +166,15 @@ put link on blackboard - class interact
* Client Layout Framework (styles + visuals)
* Assignments
* Set Today
* Assignment 1 - Digital Artifact - Due 12th December
* Assignment 2 - Technical Report - Due 9th January
* Assignment 1 - Digital Artifact - Due 11th December
* Assignment 2 - Technical Report - Due 8th January
* Tools
* Cloud based IDE + containers
* OpenAPI Spec


### Run it yourself (1 hour)
Run it yourself (30 min)
------------------------

* Cloud based VSCode IDE
* GitHub CodeSpaces
Expand All @@ -159,34 +186,47 @@ put link on blackboard - class interact
Demo:
1. The IDE
2. The Interaction (public port)
*
* launch containers
* make ports public
3. Add an item with the web interface
* Remember to add the querystring for the server `?api=` e.g. `https://8001-xxxx.ws-eu67.gitpod.io?api=https://8000-xxxxx.ws-eu67.gitpod.io`
4. Access another persons public port + Add an item to another persons server
5. Run the tests
* `make test_example_server`
* `make test_example_client`
* download video
* (Demo this natively to show Cypress interface. We will return to this in session 4 in more detail)


Task: Fork + Run + Commit
Task: Fork + Run + Commit (30 min)
----
1. Fork your own copy of the repo (description)
* Allow CI
* And enable _GitHub Actions/Workflows_
2. Start a Cloud based IDE for YOUR FORK
* `https://gitpod.io#PASTE_YOUR_GITHUB_FORK_URL_HERE`
* `https://codespaces.new/<USERNAME>/<REPO_NAME>`
* `https://gitpod.io#PASTE_YOUR_GITHUB_FORK_URL_HERE`
3. Make a commit to `/server/Dockerfile` and see CI
* ```Dockerfile
FROM python:alpine
WORKDIR /app/
COPY . .
CMD ["python", "-m", "http.server", "8000"]
```
* `git status`
* `git diff`
* `git commit -a`
* `git push`
4. See you test report online on GitHub
* GitHub -> YOUR FORK -> Actions -> `test_server` -> server-junit
* or
* commit -> red 'x' next to commit -> test_server/server-junit (push)


Workspace Hygiene
------------------
* Commit + push: every time any progress is made (even one or two lines of code)
* Your workspaces are ephemeral and should be disposed periodically - workspaces are not a datastore
* Stop your cloud IDE's (save your hours)
* Stop your cloud IDE's (save your cloud hours)
* `gp stop`
* `gh codespace stop`
* Manage/Delete unused workspaces (remove unused workspaces)
Expand All @@ -197,6 +237,24 @@ Workspace Hygiene
* [GitHub Student Developer Pack](https://education.github.com/pack) - with cccu address + cccu id
Plenary (30min)
-------
* What is Assignment 1
* How will you be assessed
* What is Assignment 2
* How will you be assessed
* Look at the session overview outlines
* How will you be supported
* Review Key Terminology
* What is a container?
* Why do we construct software in containers?
* Why is this module level 6?
* Why is this module relevant/important?
* How are you feeling?
Unsorted
========
Expand Down Expand Up @@ -259,11 +317,12 @@ Updated
3. Haskell (X)
4. Prolog
5. Java
6. What are websockets used for?
6. What are WebSockets used for?
1. Downloading files from websites
2. Used to serve websites sites via HTTP on a known port
3. Websockets are an abstract concept
4. Enabling browser based apps to have ongoing bi-directional communication (X)
3. WebSockets are an abstract concept based on REST
4. Browser based apps to have persistent bi-directional communication (X)
5. Accelerates websites with use of more modern protocols
7. `git pull --rebase` is used for
1. Refreshing a repository content with the upstream
2. Replaying local commits over remote changes to make a linear history (X)
Expand All @@ -280,6 +339,7 @@ Updated
2. Markdown (X)
3. LaTex
4. Python
5. HTML



Expand Down
67 changes: 49 additions & 18 deletions docs/01b web-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,33 @@ JSON

Moved to [TeachProgramming -> Language Features](https://github.com/calaldees/TeachProgramming/blob/master/teachprogramming/static/projects/language_features/json.md)

Understand that dynamic languages are good tools for dealing with unstructured ad-hock data structures. Static languages this type of operation is much more difficult.


OpenAPI (30min)
-------

* [redocly - FreeCycle](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/calaldees/frameworks_and_languages_module/main/openapi.yaml)

* [OpenAPI Sample Pet Store](https://redocly.github.io/redoc/)
* VSCode extension: OpenAPI preview (auto generated from yaml)
* [VSCode extension](https://marketplace.visualstudio.com/items?itemName=42Crunch.vscode-openapi): OpenAPI preview (auto generated from yaml)
* https://swagger.io/specification/
* https://redocly.com/docs/redoc/deployment/cli/
* ```bash
alias redocly='docker run --rm -v "$PWD:/spec" -u $(id -u):$(id -g) redocly/cli'
redocly build-docs openapi.yaml -o openapi.html
```
* ReDocly
* From https://redocly.com/docs/redoc/deployment/cli/
* ```bash
alias redocly='docker run --rm -v "$PWD:/spec" -u $(id -u):$(id -g) redocly/cli'
redocly build-docs openapi.yaml -o openapi.html
```
* already available for you `make openapi.html`
* [redocly - FreeCycle](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/calaldees/frameworks_and_languages_module/main/openapi.yaml) (only if you're logged into GitHub because you need access to `raw.githubusercontent.com`)
* https://editor.swagger.io/
* https://editor-next.swagger.io/



### using curl to perform HTTP posts

* `POST` example (with JSON data)
* ```bash
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data
curl -X POST http://localhost:3000/data -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}'
```

### cURL commands to add an item and read it back
Expand All @@ -137,27 +141,54 @@ OpenAPI (30min)
# for GitPod - https://8000-aaa-bbb-1234abcd.ws-eu00.gitpod.io/
# notice the http(s) differences and where the port is
curl -X POST http://localhost:8000/item -H "Content-Type: application/json" -d '{"user_id": "user1234", "keywords": ["hammer", "nails", "tools"], "description": "A hammer and nails set. In canterbury", "lat": 51.2798438, "lon": 1.0830275}'
curl http://localhost:8000/items
curl http://localhost:8000/item/1
curl http://localhost:8000/items?user_id=user1234
curl -X GET http://localhost:8000/items
curl -X GET http://localhost:8000/item/1
curl -X GET http://localhost:8000/items?user_id=user1234
curl -X DELETE http://localhost:8000/item/1
```

(Advanced tip)
You can pipe `|` the output of curl into another command/process - `jq` formats json in a terminal (and can provide other filtering/query features)
`curl https://jsonplaceholder.typicode.com/posts/1 | jq`

### Task

Run my example_server. Either with raw python or starting container.
Run `make run_example_server`. Either with raw python or starting container.

* Using cURL
* reminder - use `-vvv` to see more debug details
* Add 4 items
* with different lat/lon and user_id
* use /items/? to query different items
* Open the port - get a friend to add an item to your server
* use `/items/???` to query different items
* Open public port - give a friend your server url
* get a friend to add an item to your server
* Read another servers list of items
* (Advanced) do this in javascript (see notes below)


### Further API Practice
* [JSONPlaceholder/guide](https://jsonplaceholder.typicode.com/guide/)
* Paste into browser or use with other languages
* This shows how to do exactly what you've done in `curl` (GET, POST with json) with javascript

* Perform a HTTP Request (like your curls above) in other languages

* Javascript GET, POST, DELETE
* [JSONPlaceholder/guide](https://jsonplaceholder.typicode.com/guide/)
* Open a 'new tab' in your browser and press `F12` (devtools) - Paste code 'console'
* Python GET, POST, DELETE


```python
import urllib.request
def urllib_request(*args, **kwargs):
request = urllib.request.Request(*args, **kwargs)
with urllib.request.urlopen(request) as response:
return response.read()
import json
def fetch_json(url, data={}, method='GET'):
return json.loads(urllib_request(url, json.dumps(data).encode('utf8'), method=method, headers={"Content-type": "application/json"}))
from pprint import pprint
pprint(fetch_json('https://jsonplaceholder.typicode.com/posts/1', method="GET"))
pprint(fetch_json('http://localhost:8000/item', {"user_id": "user1234", "keywords": ["hammer", "nails", "tools"], "description": "A hammer and nails set. In canterbury", "lat": 51.2798438, "lon": 1.0830275}, method='POST'))
pprint(fetch_json('http://localhost:8000/items', method="GET"))
```
4 changes: 2 additions & 2 deletions server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ DOCKER_IMAGE:=server
build:
docker build --tag ${DOCKER_IMAGE} .

test:
docker run --rm ${DOCKER_IMAGE}
run:
docker run --rm -it --publish 8000:8000 ${DOCKER_IMAGE}
3 changes: 3 additions & 0 deletions test_server/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ def test_items_contains_from_post(ENDPOINT, item_factory):


def test_ids_generated_are_unique(ENDPOINT, new_item, get_items, item_factory):
"""
It is expected that ID's are unique. Most systems expect to not reuse ID's.
"""
ids = tuple(item['id'] for item in get_items())
for id in ids: # DELETE all items
requests.delete(f"{ENDPOINT}/item/{id}")
Expand Down

0 comments on commit 0e8a782

Please sign in to comment.