US Congress Stock Trading API examples & templates
Use these vals as a playground to view and fork US Congress Stock Trading API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
rozek
GDI_FormUploadService
HTTP
This val is part of a series of examples to introduce "val.town" in my computer science course at
Stuttgart University of Applied Sciences . The idea is to motivate even first-semester students not to wait but to put their
ideas into practice from the very beginning and implement web apps with
frontend and backend. It contains a simple HTTP end point which expects values from an HTML form that
were submitted in a POST request. The values are collected in a JSON structure
and then sent back to the client. This val is the companion of https://rozek-gdi_formupload.web.val.run/ which contains the browser part (aka "frontend") for this example. The code was created using Townie - with only a few small manual corrections. This val is licensed under the MIT License.
0
karfau
isRequest
Script
A type guard for vals that expect a WebApi Request as the first parameter. Since a val can be invoked by run, web, express or even email, the correct type for a web endpoint should be req?: Request | unknown . By using this type guard and handling the false case, all later code can safely access the request: export const myVal = (req?: Request | unknown) => {
if (!@karfau.isRequest(req)) {
return `This val has to be used with the web endpoint, see ${@neverstew.thisValUrl()}`;
}
if (req.method === 'GET') {
// ...
}
}
2