params 0.0.4

  • readme.md
  • Installing
  • Versions
  • 55

##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

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

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
27 / 100
Health:
Code health derived from static analysis. [more]
97 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60 / 100
Overall score:
Weighted score of the above. [more]
55

Platforms

Detected platforms: web

Platform components identified in package: html, mirrors.

Suggestions

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use params.dart.

Dependencies

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