1.0.2 • Published 6 years ago

angular-envelope v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

Angular Envelope

NPM version Build Status Coverage Status Known Vulnerabilities Downloads

A wrapper for the AngularJS $http service to allow for simpler RESTful API transactions.

Client-Side Usage

Include the script in your main template file:

<script src="/node_modules/angular-envelope/dist/envelope.js"></script>

Add the envelope dependency to the module you wish to use the service in, along with the Envelope service as a constructor argument:

angular.module("meme-central", ["envelope"])

.config(function($stateProvider) {
	$stateProvider.state("memes", {
		url: "/memes",
		templateUrl: "memes.html",
		controller: "MemesController",
		controllerAs: "memesController"
	});
})

.controller("MemesController", function(Envelope) {
	var self = this;

	Envelope.setBaseUrl("http://127.0.0.1:3000");

	self.memes = [];

	self.getMemes = function() {
		return Envelope.get(
			"memes",
			{
				categoryId: 420
			},
			{
				timeout: 6969,
				headers: {
					Authorization: "dnkroz"
				}
			},
			function(error, data, response) {
				if(error) {
					return console.error(error);
				}

				self.memes = data;
			}
		);
	};

	self.forcedMeme = function() {
		return Envelope.post(
			"memes",
			{
				title: "Uganda Knuckles",
				phrase: "u do not kno da wae."
			},
			{
				authorization: "idspispopd"
			},
			function(error, data, response) {
				if(error) {
					return console.error(error);
				}

				self.memes.push(data);
			}
		);
	};
});

Installation

To install this module:

npm install angular-envelope