This is the item API from my YouTube crash course
npm install
npm run dev
Visit http://localhost:5000/docs
The file test.http can be used to make requests if you are using the VSCode Rest Client extension
API built with Fastify
This is the item API from my YouTube crash course
npm install
npm run dev
Visit http://localhost:5000/docs
The file test.http can be used to make requests if you are using the VSCode Rest Client extension
How to run this on VS code ??
I've made some changes in the code, if you let me to collaborate, I could push you my branch. ;)
Until than if someone needs a fixed swagger:
const getItemOpts = {
schema: {
response: {
200: Item,
},
params: {
type: "object",
properties: {
id: { type: "string" },
},
},
},
handler: getItem,
}
const postItemOpts = {
schema: {
body: {
type: "object",
required: ["name"],
properties: {
name: { type: "string" },
},
},
response: {
201: Item,
},
},
handler: addItem,
}
const deleteItemOpts = {
schema: {
response: {
200: {
type: "object",
properties: {
message: { type: "string" },
},
},
},
params: {
type: "object",
properties: {
id: { type: "string" },
},
},
},
handler: deleteItem,
}
const updateItemOpts = {
schema: {
response: {
200: Item,
},
params: {
type: "object",
properties: {
id: { type: "string" },
},
},
body: {
type: "object",
required: ["name"],
properties: {
name: { type: "string" },
},
},
},
handler: updateItem,
}
I can add an item to the list of items. Verified by console.log the array at the last step of addItem controller. When the '/items' get route is hit directly after the add, I am seeing just the contents of the original 3 item array. This is opposite of the youtube tutorial at timecode 30:01 that covers this crash course.
// controller that adds item
const addItem = (req, reply) => {
const { name } = req.body;
const newItem = {
id: uuidv4(),
name
};
items = [...items, newItem];
reply.code(201).send(newItem);
console.log(items);
}
// controller that gets all items
let items = require('../items.js');
const { v4: uuidv4 } = require('uuid');
const getItems = (req, reply) => {
reply.send(items)
}
Thank you for the amazing course on youtube!!!
Best ever!
Steps to Reproduce:
I just git clone all the code.
I have the code
I got the error
The connection was rejected. Either the requested service isn’t running on the requested server/port, the proxy settings in vscode are misconfigured, or a firewall is blocking requests. Details: RequestError: connect ECONNREFUSED 127.0.0.1:5000.
No matter which port I use, I got the same error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.