IITM AppDev QUIZ 2
IITM AppDev QUIZ 2
Week 1 Lecture 1
Class BSCCS2003
Materials
Module # 1
Type Lecture
Week # 1
What is an App?
"An app is a computer software, or a program, most commonly a small, specific one used for mobile devices. The term
app originally referred to any mobile or desktop application, but as more app stores have emerged to sell mobile apps to
smartphone and tablet users, the term has evolved to refer to small programs that can be downloaded and installed at
once"
Source: Techopedia
Desktop Apps
Usually standalone
Web browsers
Mail clients
Custom frameworks
OS specific
Mobile Apps
Targeted at mobile platforms: Phones / Tablets
Week 1 Lecture 1 1
Constraints
Memory / processing
Power
Frameworks
OS specific
Cross-platform
Network!
Web Apps
The Platform
Week 1 Lecture 1 2
💻
Week 1 Lecture 2
Class BSCCS2003
Materials
Module # 2
Type Lecture
Week # 1
Components of an App
Storage
Computation
Presentation
Example
Storage
Compute
Indexing of e-mails
Searching
Presentation
Platforms
Desktop
Week 1 Lecture 2 1
Mobile
Touchscreen as I / O
Web-based
Embedded
Week 1 Lecture 2 2
💻
Week 1 Lecture 3
Class BSCCS2003
Materials
Module # 3
Type Lecture
Week # 1
Server:
Stores data
Client:
End users
Requests data
Network:
Can be local
Local systems:
Both client and the server on the system ⇒ local network / communication
Week 1 Lecture 3 1
Conceptually, it is still a networked system
Machine clients
Variants
Examples:
Databases
WhatsApp / messaging
Web browsing
Distributed - Peer-to-Peer
Data can flow both ways
This just means that some servers with high bandwidth are given higher weightage
Error tolerance
Masters / Introducers
Shared information
Examples:
BitTorrent
Blockchain-based systems
Week 1 Lecture 3 2
💻
Week 1 Lecture 4
Class BSCCS2003
Materials
Module # 4
Type Lecture
Week # 1
Software Architectures
What is a design pattern?
"A general, re-usable solution to a commonly occuring problem within a given context in software design"
Source: Wikipedia
M-V-C paradigm
Model:
View:
Controller:
The user uses the controller → to manipulate the model → that updates the view → that the user sees;
Week 1 Lecture 4 1
Other design patterns
Model-View-Adapter
Model-View-Presenter
Model-View-ViewModel
Hierarchical MVC
Presentation-Abstraction-Control
Each one of them has its own uses, but the fundamentals are very similar
Web-based
Architecture:
Client-server
Software architecture
Model-View-Controller
Week 1 Lecture 4 2
💻
Week 1 Lecture 5
Class BSCCS2003
Materials
Module # 5
Type Lecture
Week # 1
Worth understanding
Historical background
Telephone networks ~ 1890+
Physical wires tied up for duration of call even if nothing was said!
Wires occupied only when data was to be sent - more efficient use
Last link: The physical connection between my telephone and my nearest telephone exchange, it has to be tied
up to me
Aggregate all the data in one place (telephone exchange) and transmit it over a single wire at a much higher
speed (connection between telephone exchanges)
Week 1 Lecture 5 1
Data is being sent instead of voice over the wires
ARPANet - 1969
Node-to-node network
Others:
Protocol
"Inter" network
Can be carried over different underlying networks: ethernet, DECnet, PPP, SLIP
IP addresses were basically a set of 4 numbers, what they called the dotted quad notation
There are 4 numbers in the range of 0 - 255, which are separeted by dots ( . )
HyperText ~ 1989+
It was brought into one consolidated framework by Tim Berners Lee at CERN
static pages
limited styling
Week 1 Lecture 5 2
💻
Week 1 Lecture 6
Class BSCCS2003
Materials
Module # 6
Type Lecture
Week # 1
Impact on performance:
Network
Storage requirements
Web Server
Any old computer with a network connection can act as a web server
Software:
Protocol:
Week 1 Lecture 6 1
HTTP
HyperText
Containes "codes" inside that indicate special functions - how to "link" to other documents
Largely text based: client sends requests, server responds with hypertext documents
Week 1 Lecture 6 2
💻
Week 1 Lecture 7
Class BSCCS2003
Materials
Module # 7
Type Lecture
Week # 1
#!/bin/bash
while true; do
echo -e "HTTP/1.1 200 OK\n\n $(date)" |
nc -l localhost 1500;
done
$ nano server.sh
Write the above mentioned server bash script in that file, and then to run the script, type the following code on the linux
terminal
$ bash server.sh
We can send a request to the running server from another instance of linux shell
$ curl http://localhost:1500
Week 1 Lecture 7 1
$ curl -v http://localhost:1500
On incoming requests, it ran some code, generated results on the fly and returned the results to the client
Output can be in text or other format - MIME (Multipurpose Internet Mail Extensions)
GET / HTTP/1.1
Host: localhost:1500
User-Agent: curl/7.64.1
Accept: */*
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 1500 (#0)
> GET / HTTP/1.1
> Host: localhost:1500
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
* no chunk, no close, no size. Assume close to signal end
<
Thu Jun 17 08:14:55 IST 2021
Week 1 Lecture 7 2
💻
Week 1 Lecture 8
Class BSCCS2003
Materials
Module # 8
Type Lecture
Week # 1
What is a Protocol?
When both sides agree on how to talk
Nature of requests
Nature of client
Which host to connect to (if multiple hosts are there on a single server)
Response headers
cache information
Week 1 Lecture 8 1
status codes: 404 not found, etc
Use cases
GET: simple requests, search queries, etc
POST: more complex form data, large text blocks, file uploads
$ python -m http.server
When the above command is run in a given directory, if I find a file called index.html , return me that file else return me
the directory listing
Week 1 Lecture 8 2
💻
Week 1 Lecture 9
Class BSCCS2003
Materials
Module # 9
Type Lecture
Week # 1
Performance of a Website
How fast a site can be?
Latency
How much time does it take to get the response for a given request
Round-trip: 20ms
If I am continuously sending requests to a server, and I want it such that whenever I send a request, I get a response back
before I can then proceed, then
Response size
Week 1 Lecture 9 1
Response: 1KB of text (headers, HTML, CSS, JS)
Network connection = 100Mbps (Megabits per second) ≈ 10MBps (Megabytes per second) [Theoretically, it should
be 12.5MB/s]
For eg: Just imagine, that the result of some entrance exams were declared in India and if it is all trying to come out
of one server with the bandwidth of 100 Megabits per second
The server would simply crash when it is bombarded with more than 10,000 requests per second
Which means that Google server effectively need more than 80Gbps of bandwidth
Memory: YouTube
One python HTTP server process: ~6MB (measured)
Storage: Google
Index 100s of billions of web pages
Cross-reference, pagerank
Retrieval
Summary
The Web is a useful device / OS agnostic platform for apps
Built for HTTP for transport, HTML and related tech for presentation
Week 1 Lecture 9 2
💻
Week 2 Lecture 1
Class BSCCS2003
Materials
Module # 10
Type Lecture
Week # 2
Information representation
Computers work only with "bits"
Numbers
Representing Text
ASCII
Unicode
UTF-8
Information Interchange
Week 2 Lecture 1 1
Communicate through machines - either between machines or between humans
Standard "encoding"
Interpretation
What is "0100 0001"?
It is a string of bits
Character "A"
ASCII
American Standard Code for Information Interchange
'a'..'z'
'A'..'Z'
'0'..'9'
Why 7-bits?
Unicode
Allow codes for more script, characters
How many?
Week 2 Lecture 1 2
💻
Week 2 Lecture 2
Class BSCCS2003
Materials
Module # 11
Type Lecture
Week # 2
Efficiency of encoding
Efficiency
What is the most common language on the web?
As of now, it is English
Should all the characters be represented with the same number of bits?
Example:
A text document with 1,000 words, which equates to approximately 5,000 characters (including spaces)
According to the original 7-bit ASCII which was sufficient for English
7 bits × 5000 = 35,000 bits
Minimum needed to encode just 'a' - 'z', numbers and some special characters
could fit in 6-bits: 30,000 bits
Week 2 Lecture 2 1
Is this problem solvable in general?
It is impossible to encode by actual character frequency: depends on the text
Example:
Prefix Coding
1st byte 2nd byte 3rd byte 4th byte Free bits Max. expressible Unicode val.
0xxxxxxx 7 007F hex (127)
If the first bit starts with a 0, take the remaining 7 free bits as an ASCII code
Example
Source: https://www.w3.org/International/articles/definitions-characters
UTF-8
Stands for Unicode Transformation Format
Week 2 Lecture 2 2
💻
Week 2 Lecture 3
Class BSCCS2003
Materials
Module # 12
Type Lecture
Week # 2
What is Markup?
Topics
Content v/s Meaning
Types of Markup
(X)HTML
Raw content
Markup What is markup? Markup is a way of using cues or codes in the regular flow to indicate how text should be displayed. Ma
rkup is very useful to make the display of text clear and easy to understand
Types of Markup
Presentational
Procedural
Week 2 Lecture 3 1
Descriptive
Examples
Microsoft Word, Google Docs, etc
Focus on meaning
Fun fact: The current raw document was written in LaTeX and rendered to a PDF later
Semantic Markup
Content v/s Presentation
Semantics
Week 2 Lecture 3 2
💻
Week 2 Lecture 4
Class BSCCS2003
Materials
Module # 13
Type Lecture
Week # 2
Introduction to HTML
Topics
HyperText Markup Language
Generalizations
Variants of Interest
HTML Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading.</h1>
<p>My first paragraph.</p>
</body>
</html>
Week 2 Lecture 4 1
Tags
<h1></h1> - paired tags
Case insensitive
Nesting
Valid syntax
<em><strong>Hello</strong></em>
The output is
Hello
Invalid:
<em><strong>Hello</em></strong>
<em><strong>Hello</em>
<em><strong>Hell<o/em></strong>
<b>Hello</b>
Hello
Timelines
SGML based
1995 - HTML 2
1997 - HTML 3, 4
XML based
HTML 5
HTML 5
Block element: <div>
<center>
<font>
Week 2 Lecture 4 2
Document Object Model (DOM)
The Document Object Model (DOM) is a programming interface for web documents. It
represents the page so that programs can change the document structure, style, and content.
The DOM represents the document as nodes and objects; that way, programming languages
can interact with the page.
Source: https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction
<html>
<head>
<title>My title</title>
</head>
<body>
<h1>A heading</h1>
<a href="https://onlinedegree.iitm.ac.in">Link text</a>
</body>
</html>
document
Root element:
<html>
Element:
<head>
Element:
DOM
<title>
Document Object Model
Text:
Element:
"My title"
<body>
Element:
<h1>
Text:
"A heading"
Element: Attribute:
<a> href
Text:
"Link text"
Source: https://en.wikipedia.org/wiki/Document_Object_Model
Canvas
Offline
Web Storage
...
In most of the cases, when we talk about manipulating the DOM, we use JavaScript
Week 2 Lecture 4 3
💻
Week 2 Lecture 5
Class BSCCS2003
Materials
Module # 14
Type Lecture
Week # 2
Introduction to Styling
Topics
Markup v/s Style
Themes
CSS
<h1>Hello</h1>
https://codepen.io/21f1003586/pen/bGRoJJX
https://codepen.io/21f1003586/pen/BaZweBX
Separation of Styling
Style hints in separate blocks
Themes
Week 2 Lecture 5 1
Style sheets
Week 2 Lecture 5 2
💻
Week 2 Lecture 6
Class BSCCS2003
Materials
Module # 15
Type Lecture
Week # 2
Example:
Internal CSS
Embed inside the <head> tag
Now, all the <h1> tags in the document will look the same - centrally modified
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
External CSS
Extract common content for re-use
Week 2 Lecture 6 1
Multiple CSS files can be included
Responsive Design
Mobile and Tablet devices have smaller screen
Bootstrap
Most commonly used framework for CSS
Buttons
Forms
Icons
...
JavaScript
It is an interpreted language brought into the browser
CSS is not a programming language too (There are ways to make it Turing complete, google it)
Summary
Presentation - Human interaction
Markup - HTML
Styling - CSS
Week 2 Lecture 6 2
💻
Week 3 Lecture 1
Class BSCCS2003
Materials
Module # 16
Type Lecture
Week # 3
Overview of MVC
Outline
MVC paradigm
Accessibility
Model-View-Controller
Origins: Smalltalk-80
Design Patterns
Common software patterns
Week 3 Lecture 1 1
Running Example
Student Gradebook
Student list
Course list
Student-Course marks
Histograms
Week 3 Lecture 1 2
💻
Week 3 Lecture 2
Class BSCCS2003
Materials
Module # 17
Type Lecture
Week # 3
Views
User Interface Design
User Interface
Screen
Audio
Vibration (haptics)
User Interaction
Keyboard / Mouse
Touchscreen
Spoken voice
Custom buttons
Types of Views
Week 3 Lecture 2 1
Fully static
Partly dynamic
Mostly dynamic
Output
HTML - most commonly used - direct rendering
Dynamic images
Week 3 Lecture 2 2
💻
Week 3 Lecture 3
Class BSCCS2003
Materials
Module # 18
Type Lecture
Week # 3
Goals:
Aesthetics
Accessibility
Systematic Process
Functionality requirements gathering - What is needed?
Week 3 Lecture 3 1
💻
Week 3 Lecture 4
Class BSCCS2003
Materials
Module # 19
Type Lecture
Week # 3
Usability Heuristics
Guidelines / Heuristics
Jakob Nielsen's heuristics for design
https://www.nngroup.com/articles/ten-usability-heuristics/
General principles
Consistency
Simple language
Week 3 Lecture 4 1
💻
Week 3 Lecture 5
Class BSCCS2003
Materials
Module # 20
Type Lecture
Week # 3
Tools (part 1)
Wireframes
HTML generation
Templates
Wireframes
Visual guide to represent structure of the web page
Information design
Navigation design
Week 3 Lecture 5 1
Source: https://en.wikipedia.org/wiki/Website_wireframe
Week 3 Lecture 5 2
Source: https://www.lucidchart.com/pages/wireframe
Week 3 Lecture 5 3
Week 3 Lecture 5 4
Week 3 Lecture 5 5
💻
Week 3 Lecture 6
Class BSCCS2003
Materials
Module # 21
Type Lecture
Week # 3
Tools (part 2)
Programmatic HTML generation: PyHTML
Composable functions - each function generates a specific output
Example:
import pyhtml as h
t = h.html(
h.head(
h.title('Test page')
),
h.body(
h.h1('This is a title'),
h.div('This is some text'),
h.div(h.h2('inside title'),
h.p('some text in paragraph'))
)
)
print(t.render())
def f_table(ctx):
return (
tr(
td(cell) for cell in row
Week 3 Lecture 6 1
) for row in ctx['table']
)
Templates
Standard template text
Placeholder / Variables
Examples:
Genshi
Mako
...
Jinja
Ties in closely with Flask
Jinja example
t = Template('My favourite numbers: {% for n in range(1, 10) %}{{ n }} ' '{% endfor %}')
print(t.render())
Week 3 Lecture 6 2
💻
Week 3 Lecture 7
Class BSCCS2003
Materials
Module # 22
Type Lecture
Week # 3
Accessibility
Various forms of disability or impairment
Vision
Speech
Touch
Sensor-Motor
Standards
Interplay between many components of a page:
Principle - Preceivable
Provide text alternatives for non-text content
Week 3 Lecture 7 1
Create content that can be presented in different ways, including by assistive technologies, without losing meaning.
Principle - Operation
Make all functionality available from a keyboard
Principle - Understandable
Make the text readable and understandable
Principle - Robust
Maximize compatibility with current and future user tools
Aesthetics
Visual appearance
Very important
Simplicity preferred
Source:
Week 3 Lecture 7 2
iOS: A visual history
In what is widely regarded as his greatest presentation ever, Apple's Steve Jobs introduced the iPhone
to the world on January 9th, 2007. In the five-plus years since then, the iPhone, iPad, and iPod Touch
have literally redefined the entire world of mobile computing.
https://www.theverge.com/2011/12/13/2612736/ios-history-iphone-ipad
Summary
View - any screen seen by the human or machines
Week 3 Lecture 7 3
💻
Week 4 Lecture 1
Class BSCCS2003
Materials
Module # 23
Type Lecture
Week # 4
Persistent Storage
Example: Gradebook
Students: ID, name, address, ...
Gradebook Gradebook
Week 4 Lecture 1 1
Spreadsheets
Arbitrary data organized into rows and columns
Relationships
Students - Course?
Separate entry with full details - student name, ID, address, course ID, name, department, etc.
Redundant
Only ID specified
A B C
MAD001 BT1010 78
MAD002 EE1001 30
MAD005 EE1001 68
MAD009 AM1100 62
MAD012 AM1100 77
MAD007 BT1010 41
Questions
How should the underlying data should be stored?
Week 4 Lecture 1 2
💻
Week 4 Lecture 2
Class BSCCS2003
Materials
Module # 24
Type Lecture
Week # 4
Duplicate names?
Objects
Week 4 Lecture 2 1
class Student:
id_next = 0 # Class variable
def __init__(self, name):
self.name = name
self.id = Student.id_next
Student.id_next += 1
class Student:
id_next = 0 # Class variable
def __init__(self, name, hostel):
self.name = name
self.id = Student.id_next
self.hostel = hostel
Student.id_next += 1
Spreadsheets
Naturally represent tabular data
Arbitrary data
NoSQL
MongoDB
CouchDB
...
Week 4 Lecture 2 2
Flexible, but potential loss of validation
Week 4 Lecture 2 3
💻
Week 4 Lecture 3
Class BSCCS2003
Materials
Module # 25
Type Lecture
Week # 4
Many to Many:
Example: assign labels to emails - one email can have many labels and vice-versa
Diagrams
Entity-Relationship (ER)
Class relation
Week 4 Lecture 3 1
Entity-Relationship Diagram
ER examples
Week 4 Lecture 3 2
💻
Week 4 Lecture 4
Class BSCCS2003
Materials
Module # 26
Type Lecture
Week # 4
SQL
Relational Databases - SQL
From IBM ~ 1970s
Queries
Retrieve data from a database
Quite verbose
Inner join
Week 4 Lecture 4 1
Outer join
Cartesian product
N entries in table 1
M entries in table 2
SELECT s.name
FROM Student s
JOIN StudentsCourses sc ON s.IDNumber = sc.studentID
JOIN Courses c ON c.ID = sc.courseID
WHERE c.name = 'Calculus';
Summary
Models - persistent data storage
Mechanisms:
csv
spreadsheets
SQL
NoSQL
Week 4 Lecture 4 2
Entities and Relationships
Week 4 Lecture 4 3
💻
Week 5 Lecture 1
Class BSCCS2003
Materials
Module # 27
Type Lecture
Week # 5
MVC Origins
Model-View-Controller
Week 5 Lecture 1 1
From: Trygve Reenskaug
MODELS-VIEWS-CONTROLLERS
MODELS
Models represent knowledge. A model could be a single object (rather uninteresting), or it could be some structure of
objects. The proposed implementation supports knowledge represented in something resembling semantic nets (If I
understand Laura correctly)
VIEWS
A view is a (visual) representation of its model. It would ordinarily highlight certain attributes of the model and suppress
others. It is thus acting as a presentation filter.
A view is attached to its model (or model part) and gets the data necessary for the presentation from the model by asking
questions. It may also update the model by sending appropriate messages. All these questions and messages have to be
in the terminology of the model, the view will therefore have to know the semantics of the attributes of the model it
represents. (It may, for example, ask for the model's identifier and expect an instance of Text, it may not assume that the
model is of class Text)
CONTROLLERS
A controller is the link between a user and the system. It provides the user with input by arranging for relevant views to
present themselves in appropriate places on the screen. It provides means for user output by presenting the user with
menus or other means of giving commands and data. The controller receives such user output, translates it into the
appropriate messages and pass these messages on .to one or more of the views.
A controller should never supplement the views, it should for example never connect the views of nodes by drawing
arrows between them.
Conversely, a view should never know about user input, such as mouse operations and keystrokes. It should always be
possible to write a method in a controller that sends messages to views which exactly reproduce any sequence of user
commands.
Week 5 Lecture 1 2
General Concept - Action
Take action in response to user input
Applicability
Originally designed for GUI applications
Web?
Present Context
MVC is a good conceptual framework to understand separation of concerns
The web in general does not have the close knit structure of GUI applications needed for MVC
Other aspects of static typing and type inference of objects also broken in Python-like languages
Week 5 Lecture 1 3
💻
Week 5 Lecture 2
Class BSCCS2003
Materials
Module # 28
Type Lecture
Week # 5
Request - Response
Web is based completely on requests and responses
HTTP GET
HTTP POST
Constraints?
Any "page" can be requested
Week 5 Lecture 2 1
Example: Gradebook
Students: ID, name, address, ...
Common Operations
Create a new student - add name, roll number, date of birth, ...
Week 5 Lecture 2 2
💻
Week 5 Lecture 3
Class BSCCS2003
Materials
Module # 29
Type Lecture
Week # 5
CRUD
Types of operations - Create
Create a new entry
Update marks
Week 5 Lecture 3 1
Un-enroll students from course
CRUD
Create - Read - Update - Delete
Client only needs to know the API - now how the server implements the database, for example
Deals only with the data model life cycle - other control aspects possible
Week 5 Lecture 3 2
💻
Week 5 Lecture 4
Class BSCCS2003
Materials
Module # 30
Type Lecture
Week # 5
Other actions:
send email
update logs
Controller!
Week 5 Lecture 4 1
Summary
Actions: Interaction between view and model
Rules of Thumb
Should be possible to change views without the model ever knowing
Should be possible to change the underlying storage of model without views ever knowing
In practice:
Views and controllers tend to be more closely inter-linked than with Models
Week 5 Lecture 4 2
💻
Week 5 Lecture 5
Class BSCCS2003
Materials
Module # 31
Type Lecture
Week # 5
Stateless: Server does not know the present state of the client
Must be ready to respond to whatever the client requests without assuming anything about the client
Python Decorators
Add extra functionality on top of a function
Return a function that does something before calling the inner function
Week 5 Lecture 5 1
@app.route('/')
def home():
return 'Hello, World!'
HTTP verbs
@app.route('/'. methods=['GET'])
def index():
...
@ppa.route('/create', methods=['POST'])
def store():
...
CRUD-like functionality
@app.route('/', method=['GET'])(index)
@app.route('/create', method=['POST'])(store)
@app.route('/<int:user_id>', method=['GET'])(show)
@app.route('/<int:user_id>/edit', method=['POST'])(update)
@app.route('/<int:user_id>', method=['DELETE'])(destroy)
Summary
Flask is not natively MVC
Week 5 Lecture 5 2
💻
Week 6 Lecture 1
Class BSCCS2003
Materials
Module # 32
Type Lecture
Week # 6
API Design
Distributed Software Architecture
Server - Clients
Assumptions?
Client authentication
Network latency?
The Web
Client - Server may be far apart
State?
Week 6 Lecture 1 1
"REpresentational State Transfer" - REST
Is a request coming from an already logged in user just because of the address?
Week 6 Lecture 1 2
Client and State interact in a uniform and predictable manner
Hypertext/media used to convey the available resources and functionality - can be discovered by client through hypertext
information from the server
JavaScript
Week 6 Lecture 1 3
💻
Week 6 Lecture 2
Class BSCCS2003
Materials
Module # 33
Type Lecture
Week # 6
REST
REST
REpresentational State Transfer
State information between client and the server explicitly transferred with every communication
Sequence
Client accesses Resource identifier from the server
HTTP
One possible protocol to carry the REST messages
Week 6 Lecture 2 1
Use the HTTP verbs to indicate action
Idempotent Operations
Repeated application of the operation is not a problem
Example:
PUT: will always create the same new resource. If already exists, may give error
DELETE: can delete only once. May error on repeated deletion, but won't change the data
CRUD
CRUD: Database operations
REST =
CRUD
But, they do work together quite well
Data Encoding
Basic HTML: for simple reasons
Data serialization for transferring complex data types over text based format
JSON
JavaScript Object Notation
Nested arrays:
{
"firstName": "John",
"lastName": "Smith",
"age": 27,
"address": {
"streetAddress": "21 2nd Street",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}
Week 6 Lecture 2 2
API data transfer format
Input to API: text - HTTP
YAML
Yet Another Markup Language: common alternative, especially for documentation and configuration
Week 6 Lecture 2 3
💻
Week 6 Lecture 3
Class BSCCS2003
Materials
Module # 34
Type Lecture
Week # 6
REST APIs
CRUD
Variants of listing
Specialized functions
History of a page
JSON output
curl "https://en.wikipedia.org/w/rest.php/v1/search/page?q=earth&limit=1"
Response
{
"pages": [
{
"id": 9228,
"key": "Earth",
"title": "Earth",
"excerpt": "<span class=\"searchmatch\">Earth</span> is the third planet from the Sun and the only astronomical object known to harbour and support life. About 29.2% of <span class=\"searc
"description": "Third planet from the Sun in the Solar System",
"thumbnail": {
"mimetype": "image/jpeg",
"size": null,
"width": 200,
"height": 200,
"duration": null,
"url": "//upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/200px-The_Earth_seen_from_Apollo_17.jpg"
}
}
]
}
Documentation
Week 6 Lecture 3 1
Detailed Documentation
Week 6 Lecture 3 2
💻
Week 6 Lecture 4
Class BSCCS2003
Materials
Module # 35
Type Lecture
Week # 6
REST APIs
Example #2: CoWin public APIs
For Co-Win app: Vaccine registration and information
Unauthenticated APIs:
Authenticated APIs:
Book appointment
https://apisetu.gov.in/public/marketplace/api/cowin#/
General Information
Week 6 Lecture 4 1
Example: Availability API
{
"errorCode": "USRRES0001",
"error": "Input parameter missing"
}
Week 6 Lecture 4 2
$ curl -X GET "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPin?pincode=600020&date=04-08-2021"
-H "accept: application/json" -H "Accept-Language: en_US"
{"sessions":[
{"center_id":604384,
"name":"Fortis Malar Hospital",
"address":"Fortis Malar HospitalChennai TN.",
"state_name":"Tamil Nadu",
"district_name":"Chennai",
"block_name":"Adyar",
"pincode":600020,
"from":"13:30:00","to":"15:30:00","lat":12,"long":80,"fee_type":"Paid",
"session_id":"d40bd2c9-0f42-4948-b794-e3c31fa7c3cc",
"date":"04-08-2021",
"available_capacity":85,
"available_capacity_dose1":40,
"available_capacity_dose2":45,
"fee":"1250", . . .
curl -X GET
"https://cdn-api.co-vin.in/api/v2/registration/certificate/public/download?ben
eficiary_reference_id=1234567890123" -H "accept: application/json" -H
"Accept-Language: en_US" -H "User-Agent: Mozilla/5.0"
Unauthenticated access!
Authentication
Many APIs must be protected:
Securely give token only when the user logs in - Google OAuth, Facebook, etc.
API key: One time token that user downloads - can be copied, so potentially less secure unless combined with other
methods
Summary
API examples: CoWin, Google Cloud, Twitter, GitHub,... etc.
Week 6 Lecture 4 3
💻
Week 6 Lecture 5
Class BSCCS2003
Materials
Module # 36
Type Lecture
Week # 6
OpenAPI
APIs of interest for web apps
Purpose: information hiding — neither server nor the client should know the details of the implementation on the
other side
Documentation
Highly subjective — some programmers better than others at documenting
Incomplete — what one programmer finds important may not match others
Outdated
Description files
Machine readable — has very specific structure
Boilerplate code
Mock servers
Example: Assembly language is a version of the programming language of computers that is both machine and
human readable
Week 6 Lecture 5 1
Structured, so that it can be compiled
Week 6 Lecture 5 2
💻
Week 6 Lecture 6
Class BSCCS2003
Materials
Module # 37
Type Lecture
Week # 6
eg:
openapi: 3.1.0
info:
title: A minimal OpenAPI document
version: 0.0.1
paths: {} # No endpoints defined
Endpoints List
Week 6 Lecture 6 1
Source: https://oai.github.io/Documentation/specification-paths.html
Paths
openapi: 3.1.0
info:
title: Tic Tac Toe
description: |
This API allows writing down marks on a Tic Tac Toe board
and requesting the state of the board or of individual squares
version: 1.0.0
paths:
/board:
...
Operations
paths:
/board:
get:
...
put:
...
Operation object
paths:
/board:
get:
summary: Get the whole board
description: Retrieves the current state of the board and the winner.
parameters:
...
responses:
...
Responses
paths:
/board:
get:
responses:
"200":
...
"404":
...
Response Objects
paths:
/board:
get:
responses:
"200":
description: Everything went fine.
Week 6 Lecture 6 2
content:
...
Content Specification
content:
application/json:
...
text/html:
...
text/*:
...
Schema
content:
application/json:
schema:
type: integer
minimum: 1
maximum: 100
Complex schema
content:
application/json:
schema:
type: object
properties:
productName:
type: string
productPrice:
type: number
Parameters
paths:
/users/{id}:
get:
parameters:
- name: id
in: path
required: true
Request body
requestBody:
content:
application/json:
schema:
type: integer
minimum: 1
maximum: 100
Best practices
Design-first v/s Code-first
Week 6 Lecture 6 3
Automated tools, editors — make use of them
Week 6 Lecture 6 4