npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-http-case-converter

v0.1.3

Published

A module providing simple way to convert request params and response body of backend requests

Downloads

1,263

Readme

#ee.$http.CaseConverter Build Status Built with Grunt

Module provides a way to convert requests and responses on the fly in a drop-in manner.

Table of Contents generated with DocToc

How it works?

Module attaches http interceptors which will transform request/response parts. It is configurable which requests/responses will be processed. By default all requests with parameters and all JSON responses are processed but you may use eeHttpCaseConverterProvider to change the semantics of conditions if you need to.

How to use?

Decide what type of conversion you want to use. Currently the package provides modules:

  • ee.$http.CaseConverter.request.camelToSnake that converts request params case from camel case used in the AngularJS application to snake case (a.k.a. underscore notation) used in the backend which is a default for many popular backend REST API solutions such as Symfony FOSRestBundle and Django Rest Framework.

  • ee.$http.CaseConverter.response.snakeToCamel that converts response JSON objects from snake case to camel case.

All you have to do is to depend your main module on the chosen package modules:

var myApp = angular.module('app', [
    'ee.$http.CaseConverter.request.camelToSnake',
    'ee.$http.CaseConverter.response.snakeToCamel',
])

The most basic filtering of requests is already provided. By default

  • requests with params defined have params processed,
  • POST and PUT requests (only those may have data) with data defined have data processed
  • each response returned as application/json is processed.

You may adjust those defaults by providing requestUrlFilter or responseUrlFilter function to eeHttpCaseConverterProvider. The function should return true for URLs which should be processed and false otherwise:

myApp.config(function (eeHttpCaseConverterProvider) {
    eeHttpCaseConverterProvider.responseUrlFilter = function (url) {
        // Your custom logic to decide whether process responses or not. Should return a boolean.
    }

    eeHttpCaseConverterProvider.requestUrlFilter = function (url) {
        // Your custom logic to decide whether process requests or not. Should return a boolean.
    }
})

If URL filtering is not enough You may also use eeHttpCaseConverterProvider to define custom conditions under which processing takes place. If you wish only certain requests/responses to be process use:

myApp.config(function (eeHttpCaseConverterProvider) {
    eeHttpCaseConverterProvider.requestConfig = {
        camelToSnake: {
            params: function (requestConfig) {
                // Your custom logic to decide whether to process `params` or not. Should return a boolean.
            },
            data: function (requestConfig) {
                // Your custom logic to decide whether to process `data` or not. Should return a boolean.
            }
        }
    }
    eeHttpCaseConverterProvider.responseConfig = {
        snakeToCamel: function (response) {
            // Your custom logic to decide whether to process `response.data` or not. Should return a boolean.
        }
    }
})

#License

The module is available under the MIT license (see LICENSE for details).