Last active
March 31, 2020 08:49
-
-
Save g4s8/713666cff4626c1c689aeb18800c88d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// some kind of web app | |
class WebApp extends HttpWebApp { | |
WebApp() { | |
// creating new file object for composing with read and write handlers | |
this(new File("/tmp/1")); | |
} | |
// composition? | |
WebApp(File file) { | |
super( | |
// routes only PUT requests | |
new HttpPut( | |
new FileSave(file) | |
), | |
// routes only GET requests | |
new HttpGet( | |
new FileRead(file) | |
) | |
) | |
} | |
} | |
// file definition | |
interface File { | |
void write(byte[] data); | |
byte[] read(); | |
} | |
// http endpoint to save content to file | |
class FileSave { | |
File file; | |
Response response(Request req) { | |
file.write(req.data()); | |
} | |
} | |
// http endpoint to read content from file to response | |
class FileRead { | |
File file; | |
Response response(Request req) { | |
return file.read(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment