1.0.3 • Published 4 years ago
@apimanager/logger v1.0.3
API Logger
NPM package that will monitor & log your API usage. It's very easy to install and will help you discover API improvements, timings & security issues. It's created and used in ProductBuilders' APIManager
Installation
npm install @apimanager/logger --save
Usage
APILogger as (main) middleware
const APILogger = require('@apimanager/logger'); // Import the APILogger package
const express = require('express'); // Import a HTTP server (eg. ExpressJS)
// Create your APP
const app = express();
// Configure your APP to listen to incoming calls
app.use(APILogger.listen({
domain: 'example.com',
apiKey: 'xxxxx',
apiHost: 'YOURAPIHOST'
}));
// Start your application
app.listen(3000, () => {
console.log('Your app started on port 3000');
});
Or you can use it in a single endpoint
const express = require('express'); // Import a HTTP server (eg. ExpressJS)
// Create your APP
const app = express();
const APILogger = require('@apimanager/logger').listen({
domain: 'example.com',
apiKey: 'xxxxx',
apiHost: 'YOURAPIHOST'
})
// Configure your APP to listen to incoming calls
app.get('/', APILogger, (req, res){
res.end('Hello world');
});
// Start your application
app.listen(3000, () => {
console.log('Your app started on port 3000');
});
Important note
We try to optimise this library and our (big data) storage as much as possible. Therefore, we've renamed all the fields to a way smaller format.
The data we store is:
m: String, // Method => GET, PUT, DELETE, POST
u: String, // Url => URL including query params
p: String, // path => The clean path
h: String, // hostname => Blocked if localhost
pr: String, // protocol => HTTP or HTTPS
i: String, // IP address
ua: String, // The user agent
t: Number, // Time it took to response
c: Number, // The official status code
b: Object, // IF POST or Put, the body
ca: Date, // CreatedAt
Possible settings
- key => Your API key, unique for each project (required)
Contribute
# To publish this package. Do:
npm publish --access public
Roadmap
- Terminal resize
Copyright
APIManager