- Request and Response are both basic TS interfaces and express interfaces. You want to use the express one, so remember to import them correctly.
- NextFunction is the interface for next() and is also imported from ExpressJS.
- Async functions return Promises (which, in the TS language is
Promise<T>
whereT
is the type of data the Promise will return if fullfilled). In case of Express endpoints, you will useres.send()
, not return, soT
will bevoid
.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Esempio di file upload usando FormData e Typescript | |
//Component.jsx | |
import { ChangeEvent, FormEvent, useState } from "react" //ChangeEvent e FormEvent sono i tipi degli eventi onChange e onSubmit | |
export const Component = () => { | |
const [fd, setFd] = useState(new FormData()) //FormData e' una classe usata per raccogliere dati non stringa dai form | |
//E' formata da coppie chiave/valore => ["post", File], ["exp", File] | |
const handleSubmit = async (ev: FormEvent) => { | |
ev.preventDefault() | |
let res = await fetch( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Esempio di file upload usando FormData e Typescript | |
//Component.jsx | |
import { useState } from "react" //ChangeEvent e FormEvent sono i tipi degli eventi onChange e onSubmit | |
export const Component = () => { | |
const [fd, setFd] = useState(new FormData()) //FormData e' una classe usata per raccogliere dati non stringa dai form | |
//E' formata da coppie chiave/valore => ["post", File], ["exp", File] | |
const handleSubmit = async (ev) => { | |
ev.preventDefault() | |
let res = await fetch( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ...; | |
import org.springframework.validation.BindingResult; | |
import org.springframework.validation.annotation.Validated; | |
import org.springframework.web.bind.annotation.PathVariable; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RequestParam; | |
import example.example.exceptions.BadRequestException; | |
import example.example.exceptions.ElementNotFoundException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const browser = await puppeteer.launch({ | |
headless: config.headless, | |
args: ["--no-sandbox", "--disable-setuid-sandbox"], | |
ignoreDefaultArgs: ["--disable-extensions"], | |
}) | |
const page = await this.browser.newPage() | |
await page.setRequestInterception(true) | |
page.on("request", (req) => { | |
if ( |