| Edit | Rename | Changes | History | Upload | Download | Back to Top |
Sometimes you have an application where it would be nice - either on the internet or on the intranet - to add a small server interface to your application. What do I mean by this? Visit this page. See the set of icons at the top? Those provide ways of sending a simple HTTP based message from the browser to a locally running application. What's the simplest way that could work? Why not leverage a simple web browser, but not one running on port 80?
http://localhost:8777/myApp?arguementsGoHere
in the answerFor: method, grab the arguements this way:
answerFor: aWebRequest
arguments := aWebRequest uri query.
"put code for doing something with those arguments here"
That's about it. You can parse the arguments easily and have your application integrated with a web browser right away. The next question might be, how does one create the server and the interface programmatically? That's also pretty easy:
createServer
server := self createWaveServer.
self createResponderFor: server.
server startOn: 'localhost'.
createWaveServer
server := TinyHttpServer newMinimal.
server service trapErrors: true.
server autoStart: false.
server port: 8777.
server hostname: 'localhost'.
^server
createResponderFor: server
| responder resolver |
responder := MyResponderSubclass new.
resolver := server service resolver.
resolver atPath: 'myApp' put: responder.
The nice thing is, this server has no other interfaces - not an echo, not a launch, nothing - there's really no way to access it's services other than the limited route you give it. You'll want to add some sanity checking and some error handling; look at the BottomFeeder bundle (package RSS-Server) in the public repository for an example implementation that does that.
Try it out and see how simple it really is!
| Edit | Rename | Changes | History | Upload | Download | Back to Top |