IT Project Workshop 4 === ###### tags: `it project` --- ### Rest **RE**presentation **S**tate **T**ransfer --- ### Opposed to what? SOAP **S**imple **O**bject **A**cccess **P**rotocol --- ### Opposed to what? SOAP... XML hell - coupled, verbose and from a different era --- ### Guiding Principles: Client Server separations of concerns. Data lives in a database, is accessed via a uniform interface and the client is not coupled. --- ### Guiding Principles: Stateless API requests are fully self contained, e.g. they don't take advantage of session stores. Session state is client side. (uh oh php werkers) --- ### Guiding Principles: Cacheable For performance requirements, data needs to be able to be marked as explicitly (implicitly also) marked as cacheable or non. basically just simplifies cache invalidation. --- ### Guiding Principles: Uniform Interface Interface constraints: 1. Identification of resources 2. Manipulation of resources 3. self-descriptive messages 4. hypermedia as the engine of application state --- ### Guiding Principles: Layered System Composition - hierarchy of layers that constrain how far each component can see --- ### Guiding Principles: Code on demand ... Download js scripts --- ### HTTP codes (the important ones) **200s, succcess** - **200**: Success (GET, PUT, PATCH, OPTIONS) - **201**: Created (POST) - **202**: Async Acccepted (POST, PUT) u do it l8r **400s, client bad** - **400**: Bad request (all) - **403**: Forbidden (all) - **404**: Not found (?) **500s, u gon messed up** --- ### Example - Minecraft Website > I'm building an API for a my new service! It is a website that displays minecraft servers. anyone can put their server on. --- ### Example - Minecraft Website **Resources** - Servers - name - ip - description - votes - Vote - ip (client) - server --- ### Example - Minecraft Website steps: 1. Identify Resources 2. Identify what methods u need on those resources 3. Identify payloads! --- ### Example - Minecraft Website **Methods** ``` /server [GET] /server [POST] /server/{serverId} [GET] /server/{serverId} [POST] (form data) /server/ [PUT] /vote [POST] ``` --- ### Example - Minecraft Website **Payloads** --- **Server GET** ```jsonld= { name: "serverName", uuid: "0000-0000-0000-0000", ip: "serverIP", desc: "A fun place to play w/ ur friends", votes: 0 } ``` --- ### Example - Minecraft Website **Payloads** **Vote POST** (ip address is included in headers) ```jsonld= { serverId: "0000-0000-0000-0000", diff: -1 } ``` --- ### Nice stuff Postman Newman Swagger Artillery (load testing) --- ### REPO LINK https://github.com/kvoli/minecraft-serverlist
{"metaMigratedAt":"2023-06-15T12:08:42.061Z","metaMigratedFrom":"Content","title":"IT Project Workshop 4","breaks":true,"contributors":"[{\"id\":\"097a8b2e-1817-41aa-b11f-65c49c54dbaf\",\"add\":2835,\"del\":92}]"}
    230 views