The response context.
The response context.
Optional
options: Nilable<IApiResponseOptions>Custom options.
The new instance.
import createServer from '@egomobile/http-server'
import { apiResponse } from '@egomobile/api-utils'
const app = createServer()
app.get('/', async (request, response) => {
// create a new object and write
// it to 'newObject'
apiResponse(request, response)
.withStatus(201) // set HTTP status code to 201
.withData(newObject) // set value for 'data' prop
.addMessage('Object has been created') // a simple 'info' message for the user
.addMessage({
type: 'warn'
internal: true,
message: 'A new object with ID ' + newObject.id + ' has been created'
}) // internal warning message
.send() // write all data to client
})
app.listen()
.catch(console.error)
Generated using TypeDoc
Creates a new instance, building the data for an API response.