https://github.com/streammedev/parrot-server
Simple server responds to any HTTP request with details about the request.
https://github.com/streammedev/parrot-server
Last synced: about 1 year ago
JSON representation
Simple server responds to any HTTP request with details about the request.
- Host: GitHub
- URL: https://github.com/streammedev/parrot-server
- Owner: StreamMeDev
- License: isc
- Created: 2016-12-15T00:20:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-17T21:43:48.000Z (over 9 years ago)
- Last Synced: 2024-04-29T05:41:45.558Z (about 2 years ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Parrot Server
[](https://github.com/JedWatson/happiness)
Simple server responds to any HTTP request with details about the request.
## Install
```javascript
npm install @streammedev/parrot-server;
```
## Usage
First, import the class:
```javascript
import ParrotServer from '@streammedev/parrot-server';
```
Next, instantiate it:
```javascript
const server = new ParrotServer();
```
Next, start it:
```
server.start();
```
Your server is now accepting requests at `http://localhost`.
Once you're done, stop the server by calling `stop`, ie:
```javascript
server.stop();
```
## API
`constructor(port)` - Instantiates a new server instance on the specified (optional) port. Whether it is set explicitly or not, server.port will be set to the port once the server has started.
`start(cb)` - Starts the server, then calls the (optional) callback.
`stop(cb)` - Stops the server, then calls the (optional) callback.
## CLI
A simple cli command is available:
```bash
parrot-server --port=8080
```
## Example
```javascript
import ParrotServer from '@streammedev/parrot-server';
import assert from 'assert';
import request from 'request';
describe('do some test', function () {
let testServer;
before(function (done) {
testServer = new ParrotServer(port);
testServer.start(done);
});
after(function (done) {
testServer.stop(done);
});
it('should get my endpoint', function(done) {
request('http://localhost/my-endpoint?q=findme', function (error, response, body) {
assert.ifError(error);
assert.ifError(response.statusCode !== 200);
assert.strictEqual(body.method, 'GET', 'it should be a GET request');
assert.strictEqual(body.path, 'my-endpoint', 'it should have the right path');
assert.strictEqual(body.query.q, 'findme', 'it should set the q query parameter');
})
})
})
}
```
## Contributing
Contributions are welcome.
Please see our guidelines in [CONTRIBUTING.md](contributing.md)