GithubHelp home page GithubHelp logo

mkonicek / react-native-cookies Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joeferraro/react-native-cookies

0.0 1.0 0.0 33 KB

Cookie manager for React Native

License: MIT License

Objective-C 42.82% Java 46.11% JavaScript 11.07%

react-native-cookies's Introduction

react-native-cookies

Cookie manager for react native.

Installation

  1. npm install react-native-cookies
  2. rnpm link react-native-cookies - (run npm install -g rnpm if required)
  3. Om nom nom nom cookies.

Usage

var CookieManager = require('react-native-cookies');

// set a cookie (IOS ONLY)
CookieManager.set({
  name: 'myCookie',
  value: 'myValue',
  domain: 'some domain',
  origin: 'some origin',
  path: '/',
  version: '1',
  expiration: '2015-05-30T12:30:00.00-05:00'
}, (err, res) => {
  console.log('cookie set!');
  console.log(err);
  console.log(res);
});

// Set cookies from a response header
// This allows you to put the full string provided by a server's Set-Cookie 
// response header directly into the cookie store.
CookieManager.setFromResponse('http://example.com', 'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly', (res) => {
  // `res` will be true or false depending on success.
  console.log("Set cookie", res);
})

// Get cookies as a request header string
CookieManager.get('http://example.com', (err, res) => {
  console.log('Got cookies for url', res);
  // Outputs 'user_session=abcdefg; path=/;'
})

// list cookies (IOS ONLY)
CookieManager.getAll((err, res) => {
  console.log('cookies!');
  console.log(err);
  console.log(res);
});

// clear cookies
CookieManager.clearAll((err, res) => {
  console.log('cookies cleared!');
  console.log(err);
  console.log(res);
});

// clear a specific cookie by its name (IOS ONLY)
CookieManager.clearByName('cookie_name', (err, res) => {
  console.log('cookie cleared!');
  console.log(err);
  console.log(res);
});

Roadmap

  • Proper getAll dictionary by domain
  • Proper error handling
  • Anything else?

PR's welcome!

react-native-cookies's People

Contributors

7ynk3r avatar foloinfo avatar joeferraro avatar kevinresol avatar psykar avatar pushrax avatar sdg9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.