API Endpoint Structure

I’m trying to access some API URL endpoint on an application but failing to do so. I need to getallStores by name from SQL server using the API. The application have few API URL that are used and accessed but I don’t have the structure.

Can you create your own Endpoint Structure aside? Using the same application.

Thank you.

import { WebApp } from 'meteor/webapp'

WebApp.connectHandlers.use('/trial', (req, res) => {
  // so we can call from website client-side
  res.setHeader('Access-Control-Allow-Origin', '*')
  // pre-flight request
  if (req.method == 'OPTIONS') {
    res.writeHead(200)
    res.end()
    return
  }
  req.on('data', Meteor.bindEnvironment((data) => {
    res.setHeader('Content-Type', 'application/json')
    try {
      var params = JSON.parse(data.toString())
    }
    catch(e) {
      res.writeHead(400)
      res.end()
      return
    }
    Meteor.defer(() => YOUR_FUNCTION(params))
    res.writeHead(200)
    res.end(JSON.stringify({ status: 'ok' }))
  }))
})
2 Likes

The simple:rest packages (specifically the json-routes package) make setting up REST routes very easy