New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fake-api-server

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fake-api-server - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

.travis.yml

1

lib/index.js

@@ -1,2 +0,1 @@

// Generated by CoffeeScript 1.8.0
(function() {

@@ -3,0 +2,0 @@ module.exports = {

@@ -1,2 +0,1 @@

// Generated by CoffeeScript 1.8.0
(function() {

@@ -6,4 +5,7 @@ var Resource;

Resource = (function() {
function Resource(_name) {
this._name = _name;
function Resource(_name1) {
this._name = _name1;
if (!(this instanceof Resource)) {
return new Resource(_name);
}
this._records = [];

@@ -15,10 +17,10 @@ this._idAttribute = "id";

return 1 + Math.max(0, Math.max.apply(Math, (function() {
var _i, _len, _ref, _results;
_ref = this._records;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
d = _ref[_i];
_results.push(d[this._idAttribute]);
var i, len, ref, results;
ref = this._records;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
d = ref[i];
results.push(d[this._idAttribute]);
}
return _results;
return results;
}).call(_this)));

@@ -61,3 +63,3 @@ };

} else {
return "" + this._name + "s";
return this._name + "s";
}

@@ -64,0 +66,0 @@ } else {

@@ -1,2 +0,1 @@

// Generated by CoffeeScript 1.8.0
(function() {

@@ -11,8 +10,14 @@ var Server, bodyParser, express;

function Server() {
if (!(this instanceof Server)) {
return new Server();
}
this._resources = [];
this._server = express();
this._server.use(bodyParser());
this._server.use(bodyParser.json());
this._server.on("error", function(err) {
return console.error(err);
});
}
Server.prototype._setupRoutes = function() {
this._server.get("/api", (function(_this) {

@@ -32,3 +37,3 @@ return function(req, res) {

if (!resource) {
return res.send(404);
return res.sendStatus(404);
}

@@ -44,3 +49,3 @@ return res.send(resource.all());

if (!resource) {
return res.send(404);
return res.sendStatus(404);
}

@@ -60,7 +65,7 @@ if (!(data = resource.find(req.params.id))) {

if (!resource) {
return res.send(404);
return res.sendStatus(404);
}
data = req.body;
resource.add(data);
return res.send(200);
return res.sendStatus(200);
});

@@ -73,6 +78,6 @@ };

if (!resource) {
return res.send(404);
return res.sendStatus(404);
}
if (resource.update(req.params.id, req.body)) {
return res.send(200);
return res.sendStatus(200);
} else {

@@ -85,10 +90,10 @@ res.statusCode = 404;

})(this));
this._server["delete"]("/api/:resource/:id", (function(_this) {
return this._server["delete"]("/api/:resource/:id", (function(_this) {
return function(req, res) {
return _this.find(req.params.resource, function(resource) {
if (!resource) {
return res.send(404);
return res.sendStatus(404);
}
if (resource.remove(req.params.id)) {
return res.send(200);
return res.sendStatus(200);
} else {

@@ -101,9 +106,9 @@ res.statusCode = 404;

})(this));
}
};
Server.prototype.find = function(path, cb) {
var resource, _i, _len, _ref;
_ref = this._resources;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
resource = _ref[_i];
var i, len, ref, resource;
ref = this._resources;
for (i = 0, len = ref.length; i < len; i++) {
resource = ref[i];
if (resource.pluralName() === path) {

@@ -116,7 +121,11 @@ return cb(resource);

Server.prototype["static"] = function(path) {
this._server.use(express["static"](path));
Server.prototype.use = function(middleware) {
this._server.use(middleware);
return this;
};
Server.prototype["static"] = function(path) {
return this.use(express["static"](path));
};
Server.prototype.listen = function(port) {

@@ -126,2 +135,7 @@ if (port == null) {

}
if (this._initialized) {
throw new Error("Cannot call listen more than once!");
}
this._setupRoutes();
this._initialized = true;
this._server.listen(port);

@@ -128,0 +142,0 @@ return this;

{
"name": "fake-api-server",
"version": "0.3.0",
"version": "0.4.0",
"author": "Andrew Couch <fake-api-server@andrewcou.ch>",

@@ -21,10 +21,14 @@ "description": "A simple, easy mock REST API server.",

"dependencies": {
"express": "~4.2.0",
"body-parser": "~1.2.0"
"body-parser": "^1.13.2",
"express": "^4.13.1"
},
"devDependencies": {
"chai": "~1.9.1",
"mocha": "~1.18.2",
"coffee-script": "~1.8.0"
"chai": "^3.2.0",
"coffee-script": "^1.9.3",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-coffee": "^0.13.0",
"grunt-mocha-test": "^0.12.7",
"mocha": "^2.2.5"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc