Skip to content
This repository has been archived by the owner on Mar 19, 2020. It is now read-only.

nitro404/angular-envelope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angular Envelope

NPM version Build Status Coverage Status Known Vulnerabilities Downloads

This module has been deprecated, use xhr-envelope instead.

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