Your Code
Your Code
Class Foo
Class Bar
Your Code
Class Foo
Foo.X()
Class Bar
Bar.A()
Your Code
Class Foo
Foo.X()
Foo._Y()
Class Bar
Bar.A()
Bar._B()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
Private methods used by Foo.X()
Private methods used by Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
var Foo = require('./YourCode/Foo.js');
var Bar = require('./YourCode/Bar.js');
let f = new Foo();
let b = new Bar();
f.X();
b.A();
// So much win
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
var Foo = require('./YourCode/Foo.js');
var Bar = require('./YourCode/Bar.js');
let f = new Foo();
let b = new Bar();
f.X();
b.A();
// So much win
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
var Foo = require('./YourCode/Foo.js');
var Bar = require('./YourCode/Bar.js');
let f = new Foo();
let b = new Bar();
f.X();
b.A();
// So much win
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
var Foo = require('./YourCode/Foo.js');
var Bar = require('./YourCode/Bar.js');
let f = new Foo();
let b = new Bar();
f.X();
b.A();
// So much win
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
But how to expose this service without exposing your code?
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Request
Response
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
Endpoints
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
Endpoints
/bar
/foo
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
Endpoints
/bar
/foo
that.get("/bar", Bar.A())
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
Endpoints
/bar
/foo
that.get("/bar", Bar.A())
that.get("/foo", Foo.X())
API
Foo.X()
Bar.A()
Your Code
Class Foo
Class Bar
Foo.X()
Foo._Y()
Foo._Z()
Bar.A()
Bar._B()
Bar._C()
JSON
JSON
HTTP Requests
Server
Req
Res
Endpoints
/bar
/foo
Incoming request (JSON wrapped in HTTP)
Incoming request (JSON wrapped in HTTP)
Server forwards to a endpoint
/foo
/bar
Incoming request (JSON wrapped in HTTP)
Server forwards to a endpoint
/foo
/bar
Incoming request (JSON wrapped in HTTP)
Server forwards to a endpoint
/foo
/bar
Server calls the method (Server.Foo.X())
Incoming request (JSON wrapped in HTTP)
Server forwards to a endpoint
/foo
/bar
Server calls the method (Server.Foo.X())
Foo.X() processes the request and return response
Core logic
e.g: addDataset()
Core logic
e.g: addDataset()
Server method to handle Req/Res
e.g: Server.Dataset()
Core logic
e.g: addDataset()
Server method to handle Req/Res
Endpoint that will call a server method to handle the request
e.g: that.server.put("/dataset/:id", Server.dataset())
e.g: Server.Dataset()
that.rest.put('dataset/:id', SomeClass.putDataset);
putDataset (req: restify.Request, res: restify.Response, next: restify.Next) {
// Get the dataset data coming from the request
let dataStr = new Buffer(req.params.body).toString('base64');
let iFacade = new InsightFacade();
let datasetName = req.params.id;
// Call your good old AddDataset() -- Remember it is an ASYNC function!!
// ...
// ...
// ...
// Write to response object the code you're returning
res.status(value.code);
// Write to response object the json data you're returning
res.json(value);
// Return this. Because.
return next();
}
it("It should be able to put the dataset", function () {
// Point to your local test dataset
let file = __dirname + "/rooms.zip";
// Make the request to your local machine (you are running the server locally)
return chai.request('http://localhost:4321')
.put('/dataset/rooms')
.attach("body", fs.readFileSync(file), file)
.then(function (res: restify.Response) {
//Log.trace('then:' + JSON.stringify(res));
expect(res.status).to.equal(204);
})
});