HTTP
- Describe what HTTP is and the role of the request and the response.
- HTTP is just a text sent over the internet with a set of rules that governs how computer communicates with each other. It follows a model whereby a client makes a request and then wait for a response from a server. HTTP itself doesn't transmit data, it depends on TCP/IP protocol to get request/response from one machine to another.
- What are the components of an HTTP request and an HTTP response?
- HTTP request and response has a header and body.
- HTTP response will contain status code ( 200 OK) and headers which is a metadata that contain information for content-type (text/html), Content-Encoding:gzip (type of file compression), server (name of the server), Location (new resource location for redirects) and a HTTP body
- HTTP request header contain information on HTTP method (GET/POST) , path and parameter to allow server to know how to find information, along with optional headers that include info on user-agent(chrome, mozilla), accept-language: en, cookie, connection:keep alive and optional HTTP body.
- HTTP body contain the main message of the HTTP , typically they are HTML, CSS, JAVASCRIPT, image or audio etc.
- Common types of status code
- 200 ok - the request is served fine
- 302 found - redirect the url to a new location via the header's 'Location' parameter
- 404 not found - page cannot be found
- 500 Internal server error - something wrong in the server code.
- Identify the components of a URL. Construct a URL that contains a few params and values.
- https://example.com:88/files?due=today&due=tomorrow
- https is the protocol or the scheme, it tells client how to access the resources
- example.com is the host , where the resources is hosted/located
- 88 is the port number.
- /files is the path, or where the resources is located locally
- ?due=today&due=tomorrow , this is query string, due is parameter name and today is parameter value, & is used to delimit second parameter string.
- Explain the difference between GET and POST, and know when to choose each.
- GET is used to retrieve information from a server while POST is used to write/manipulate information in a server
- GET can pass information to the server via query string. Query string has maximum length and are visible to user (password can't be sent via query string).
- POST request will store the information to be passed to server in the HTTP body. There is no size limit to the information to be sent. It is still not secured unless it is encrypted.
- What is the difference between client-side and server-side code? For each file in a Sinatra project, be able to say which it is.
Web
- How does an HTML form element interact with the server-side code that processes it.
- Why is user-entered content a security risk? Be aware of how to mitigate this risk.
- Also known as cross-site scripting. A user could write a malicious javascript that jeopardize the site to a forum comment for example. Typical way to mitigate this risk is to sanitize user's input by removing <script> tag or dissallowing JS / HTML altogether for safer format like Markdown. Or , escape all user input data when displaying it.
Sinatra
- Start a new Sinatra project and write simple routes to handle requests.
- What are the benefits of using view templates? Be able to use an ERB template in a Sinatra route.
- What is the session? Where it is stored? How it is used?
- A session is a way that web application can maintain some states/history in a stateless HTTP environment. It maintain this by exchanging a unique session ID. A common session ID is a cookie. The cookie is set by the server the first time a client visits a website. Then, the client will send the cookies back and forth with server. The server will use the cookies to retrieve session data stored in its database to serve up the webpages.
- Write a view helper and use it within a view template.
- Explain how redirection works and why it would be needed in a web application.
Comments
Post a Comment