Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you provide the rest api spec ? #1

Open
jrichardsz opened this issue May 20, 2024 · 1 comment
Open

Could you provide the rest api spec ? #1

jrichardsz opened this issue May 20, 2024 · 1 comment

Comments

@jrichardsz
Copy link

Could you provide the rest api spec?

I mean only the expected request and response

Thanks

@jrichardsz
Copy link
Author

I achieved to recreate the api

libraries

npm install express body-parser cors

server.js

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var port = process.env.PORT || 5000;
var cors = require('cors');

var tasks = [{_id: "f98decd1-0899-444b-a33f-0efc611e1b4d", title: "foo", completed: true}];

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(cors());

app.get('/api/v1/tasks', function(req, res) {
  return res.json({"tasks": tasks});
});

app.post('/api/v1/tasks/', function(req, res) {
    tasks.push({...req.body, _id: uuidv4()})
    return res.json({"code": 200000, message: "success"});
});

app.patch('/api/v1/tasks/:id', function(req, res) {
    var foundIndex = tasks.findIndex(x => x._id == req.params.id);
    tasks[foundIndex] = req.body;
    return res.json({"code": 200000, message: "success"});
});

app.delete('/api/v1/tasks/:id', function(req, res) {
  var foundIndex = tasks.findIndex(x => x._id == req.params.id);
  if(foundIndex<0) {
    return res.json({"code": 404000, message: "No todo found"});    
  }

  tasks.splice(foundIndex, 1)
  return res.json({"code": 200000, message: "success"});
});

function uuidv4() {
  return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
    (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
  );
}

app.listen(port);


console.log(`api mock is ready at ${port}`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant