params 0.1.0

##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 v 0.1.0 - '>=2.0.0-dev <3.0.0'

Use this package as a library

1. Depend on it

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


dependencies:
  params: ^0.1.0

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
27
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Jul 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: web

Platform components identified in package: html, mirrors.

Health issues and suggestions

Document public APIs. (-1 points)

8 out of 8 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/server.dart. (-1 points)

Analysis of lib/server.dart reported 2 hints:

line 1 col 2: 'MirrorsUsed' is deprecated and shouldn't be used.

line 17 col 5: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

Fix lib/client.dart. (-0.50 points)

Analysis of lib/client.dart reported 1 hint:

line 1 col 2: 'MirrorsUsed' is deprecated and shouldn't be used.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and params.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0

Admin