Skip to content

Commit

Permalink
best commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sveltemaster committed Dec 21, 2020
0 parents commit aa9c99c
Show file tree
Hide file tree
Showing 13 changed files with 1,766 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/node_modules/
/public/build/
.DS_Store
.env
.env.local
.env.build

.vercel
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Vercel Simple Serverless CRUD API

**Sign up for Vercel, then you can set up and deploy a site with..**
`$ npm intall -g vercel`
`$ vercel init svelte name_of_project` (might be prompted to connect account)
`$ cd name_of_project`
`$ npm i`
`$ vercel`
`(hit enter, enter, enter, enter)`
for override settings type..
`y, enter, down, down, space, enter, npm run dev`

**Do this to the Code**
rename api/date.js to crud.js
paste this in crud.js

```let people = [{name: 'Patrick'}, {name: 'Sandy'}, {name: 'Bob'}]
module.exports = function (req, res) {
if (req.method === 'GET') {
res.status(200).json(people);
} else if (req.method === 'POST') {
people.push(req.body)
res.status(200).json(people)
} else if (req.method === 'PUT') {
const {person, index} = req.body;
people[index] = person;
res.status(200).json(people)
} else if (req.method === 'DELETE') {
const {index} = req.body;
people = people.filter(function(_, i) { return i !== index });
res.status(200).json(people)
}
};```
**Try it out**
`$ vercel dev`
then try it at `localhost:3000/api/crud`
or
`$ vercel`
then try it out at `{the_link_it_gives_you}/api/crud`
18 changes: 18 additions & 0 deletions api/crud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let people = [{name: 'Patrick'}, {name: 'Sandy'}, {name: 'Bob'}]

module.exports = function (req, res) {
if (req.method === 'GET') {
res.status(200).json(people);
} else if (req.method === 'POST') {
people.push(req.body)
res.status(200).json(people)
} else if (req.method === 'PUT') {
const {person, index} = req.body;
people[index] = person;
res.status(200).json(people)
} else if (req.method === 'DELETE') {
const {index} = req.body;
people = people.filter((_, i) => i !== index);
res.status(200).json(people)
}
};
Loading

0 comments on commit aa9c99c

Please sign in to comment.