maven idk

Cards (33)

  • Maven does qol by handling dependencies and managing the build process.
  • Maven fetches a library for you given an XML for it
  • pom file contains details of all dependencies, language version etc.
  • @RestController denotes a class as handling rest requests
  • @GetMapping, @PutMapping etc. have "/path" variables that are counted from the base address. Can have multiple path combinations that run the same method
  • @RequestBody = the whole body as a string param
  • @PathVariable value = "val" String val: Generates a string variable from a path variable
  • @RequestParam(value = "val") String val: Query param in url
  • @RequestHeader(value = "val" String val): pass name val pair in in header(s)
  • @XMapping(value = "/", Consumes = x) consumes = accepts, produces = sends out. content-type is header to set the matching value in the request
  • @RequestParam is also used for http in body
  • required goes in @PVariable(val = "x", required = false)
  • hierarchies/categories: path params
  • random filters: query params
  • body params are useful in posts
  • for some data about a post/put object (eg. category), might need to be passed with path params
  • For delete, use path anf query to find and specify the one
  • HttpClient cli = HttpClient.newHttpClient(); - sets up a new client for coms with the server
  • HttpRequest req = HttpRequest.newBuilder().uri(new URI(url)).GET().BUILD(); - constructs request, setting URI, then type, then build command
  • HttpResponse resp = httpClient.send(httpRequest, HttpResponse.BodyHandlers()) (for string)
  • once HttpResponse has been setup, can get the body with response.body
  • asynch = not going to wait for the response, once callback triggered trigger handling of response
  • Optionals - may be empty and you know it
  • Put request build: HttpRequest.builder.URI(uri).header("name", "value").POST(HttpRequest.Body.ofString("name=x&y=z"))
  • request gen order: newBuilder > URI > headers > type > (body content) > build()
  • 400 = bad request
  • Return from server ResponseEntity<Object> rather than just Object
  • Always check post/put data is valid before actioning
  • To send as JSON, just 'send' the damn 'object'
  • JSON format: {"name": "value", "var": "value"}
  • Taking JSON in the body, can simply accept an object/list of objects
  • need a library to handle JSON
  • ObjectMapper - used to map JSON back to an object via method readValue(response.body(), new TypeReference<>(){})