morsecode-api.de
Documentation forThis website documents the installation and usage of morsecode-api.de, a side-project I created to create and play around with REST-APIs, node.js and Heroku. Since it's running there, you can also reach it under morsecodeapi.herokuapp.com.
I explained the DNS setup in a seperate blogpost (German). Both morsecode-api.de and www.morsecode-api.de should work, but the www domain is faster. You need to add the -L
parameter to cURL when using morsecode-api.de without www.
/
GET Redirects here.
/encode
GET Request
Submit one parameter string
e.g.
$ curl http://www.morsecode-api.de/encode?string=foo
Response
The response has two attributes: plaintext
and morsecode
, e.g.
{
"plaintext":"FOO",
"morsecode":"..-. --- ---"
}
/decode
GET Request
Submit one parameter string
and URL-encode the white spaces to %20
e.g.
$ curl http://www.morsecode-api.de/decode?string=-...%20.-%20.-.
Response
The response has two attributes: plaintext
and morsecode
, e.g.
{
"plaintext":"BAR",
"morsecode":"-... .- .-."
}
Sourcecode and deployment
Get the sourcecode from GitHub, install npm modules and start the app.
$ git clone https://github.com/repat/morsecode-api.git
$ cd morsecode-api
$ npm install
$ nodemon server.js
As you might have noticed, the Procfile
file is an indicator that this code could also be run on Heroku. Assuming that the Heroku Toolbelt is installed and the repository is prepared you can follow the normal instruction for deploying an app. Make sure that the port
variable is set to process.env.PORT
.
Testing
I wrote a couple of tests with frisby in frisby_spec.js
using the www.morsecode-api.de
server. If you use localhost:8080
instead, you will get an error described in issue #133. This should be the outcome:
$ jasmine-node frisby_spec.js
Testing with http://www.morsecode-api.de/
............
Finished in 2.958 seconds
12 tests, 67 assertions, 0 failures, 0 skipped
Licenses
Contact
- Homepage: http://repat.de
- e-mail: repat@repat.de
- Twitter: @repat123