How do I fetch SQL server data on my barcodescanning app?

Good day guys!

I’ve build a barcode scanning app which scans barcode and show the numbers result.
using this

Now i want to connect it to a sql server and fetch a data
For example a product data . How do i do that?

Will you suggest an REST API? how do implement it. Sorry I’m new to this.

Thank you:)

Yep, you’d need to setup an API for this. In your app, you could create an API/Backend service, kinda like the following:

import { Http, Headers, RequestOptions, RequestMethod, URLSearchParams, Response } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/timeout';


	private http: Http
) {}

post(params: Object, body: Object, timeout = 60 * 1000) {
	// Build your url using the params, if any
	let url = "";

	// Headers - Add the ones you need, if any
	let headers = {};

	// Request options
	let options = new RequestOptions({ headers: new Headers(headers) });

	// Return the Request Observable
	return, JSON.stringify(body), options)
		.map((res: Response) => res.json());

Ish. Probably needs some tweaking to suit your needs.

Edit: My apologies, I just realized you tagged this as Ionic and not Ionic 2. In that case, I’m sure you can find your way on Google to the equivalent of what I said :wink:

ok, so i’ve already setup my Rest api to connect to SQL server

I used Express for this.

Here’s the code for the barcode scanner

angular.module(‘scanner.controllers’, [])
.controller(‘HomeController’, function($scope, $rootScope, $cordovaBarcodeScanner, $ionicPlatform, $http, $ionicLoading, $ionicPopup, $timeout) {
var vm = this;

    vm.scan = function(){

    beginScan = function() {
      $ionicPlatform.ready(function() {
              .then(function(result) {
                  // Success! Barcode data is here
                  $scope.scanResults = "Barcode: " + result.text + "<br>" +
                                       "Format: " + result.format + "<br>";
              }, function(error) {
                  // An error occurred
                  $scope.scanResults = 'Error: ' + error;

My barcode scanner gets the barcode number now

Now how do i request an id or data on json

then get the specific details??