Skip to content
This repository has been archived by the owner on May 3, 2018. It is now read-only.

Latest commit

 

History

History
71 lines (60 loc) · 1.72 KB

server.md

File metadata and controls

71 lines (60 loc) · 1.72 KB

Server

createServer(app)

Create a server intance. The server object has methods for routing IPC messages as if they were HTTP requests with an API similar to what Express offers.

const { app } = require('electron')
const server = require('electron-ipc-server').createServer(app)

HTTP-like methods

server.get(path [, callback...])

server.get('/users', (req, res) =>
{
    let users = // you get the users from your backend
    res.status(200).send(users)
})

server.post(path [, callback...])

server.post('/users', (req, res) =>
{
    // create user, then...
    res.status(200).send(`user ${req.body.name} created`)
})

server.put(path [, callback...])

server.put('/users/:id', (req, res) =>
{
    // update user, then...
    res.status(200).send(`user ${req.body.name}, with id ${req.params.id}, updated`)
})

Notice we are using path parameter to capture values from the path. For more information, see Routing.

server.delete(path [, callback...])

server.delete('/users/:id', (req, res) =>
{
    // delete user, then...
    res.status(200).send(`user deleted with id ${req.params.id}`)
})

Notice we are using path parameter to capture values from the path. For more information, see Routing.

server.all(path [, callback...])

server.all('/users', (req, res) =>
{
    res.status(200).send(`catching all requests`)
})

Event methods

server.broadcast(channel, data)

server.broadcast('users-list-update', usersList)

Middleware methods

server.use([path,] callback [, callback...])

server.use(query)