params 0.0.4

  • readme.md
  • Installing
  • Versions
  • 15

##Params

Params is a package that provides window.location.search on client and request.requestedUrl.query on server as a Map

  1. install via pub

##On the client


  1. Import the package inside your client like this

     import 'package:params/client.dart';
    
  2. At the beginning of your main function call add

     await initParams();
    
  3. If the window location is http://127.0.0.1:3030/Rainbow/web/rainbow.html?id=1&language=dart the Standart client params map looks like this

     {
       id: 1, 
       language: dart, 
       _ancestorOrigins: [], 
       _hash: , 
       _host: 127.0.0.1:3030, 
       _hostname: 127.0.0.1, 
       _href: http://127.0.0.1:3030/Rainbow/web/rainbow.html?id=1&language=dart,
       _origin: http://127.0.0.1:3030, 
       _pathname: /Rainbow/web/rainbow.html, 
       _port: 3030, 
       _protocol: http:, 
       _search: ?id=1&language=dart
     }
    

Now you can access the search values using params['key'] like below

   Future main() async{
     await initParams();
     if(params['id'] != null){
       String id = params['id'];
       String language = params['language'];
       var url = http://127.0.0.1:8090/loadItem?id=$id&language=$language;
       var request = HttpRequest.getString(url).then(displayUserAccount);
     }else{
       content.text="no UserAccount id available";
     }
   };

##On the server


  1. Import the package inside your server like this

     import 'package:params/server.dart';
    
  2. At the beginning of your server.listen function add

     await initParams();
    
  3. If a HTTP request is made to http://127.0.0.1:8090/loadItem?id=1&language=dart

the standart server params map looks like this:

    {
      id: 1,
      language: dart,
      _query: id=1&language=dart, 
      _authority: 127.0.0.1:8090, 
      _host: 127.0.0.1, 
      _port: 8090, 
      _path: /loadItem, 
      _pathSegments: [loadItem], 
      _queryParameters: {
        id: 1,
        language: dart
      }, 
      _isAbsolute: true, 
      _hasAuthority: true, 
      _origin: http://127.0.0.1:8090, 
      __isPathAbsolute: true, 
      _hashCode: 277712556
    }

Now you can access the query values using params['key'] like below

   server.listen((HttpRequest request) async {
     await initParams(request);
     //if request.requestedUrl.query is "id=1&language=dart"
     String id = params['id'];
     String language = params['language'];
     switch (request.method) {
       case "GET": 
         handleGet(request);
         break;
       case "POST": 
         handlePost(request);
         break;
       case "OPTIONS": 
         handleOptions(request);
         break;
       default: defaultHandler(request);
     }
   } 

###changelog

v 0.0.4 - adopted to await async

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  params: ^0.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:params/client.dart';
import 'package:params/server.dart';
  
Version Uploaded Documentation Archive
0.0.4 Nov 6, 2016 Go to the documentation of params 0.0.4 Download params 0.0.4 archive
0.0.3 May 11, 2016 Go to the documentation of params 0.0.3 Download params 0.0.3 archive
0.0.2 May 19, 2014 Go to the documentation of params 0.0.2 Download params 0.0.2 archive
0.0.1 May 14, 2014 Go to the documentation of params 0.0.1 Download params 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
30
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
15
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=0.8.10+6 <2.0.0