Using dart discoveryapis_generator on webapp? - dart

Can't use my model file generated with the discoveryapis_generator.
It ask for a http.client to be used, but it's from dart:io, and i m trying to use it in a web app
static YoupipeApi api = new YoupipeApi(new http.Client()); //cant work on webapp
Failed to invoke tokenLoaded callback: Unsupported operation: IOClient isn't supported on this platform.
So, discoveryapis_generator is only available for native dart client?
Am i doing something wrong?
(related question here)

The http package also contains a client that runs in the browser. Just change the import to import the file package:http/browser_client.dart; instead.

Related

How can I share private libraries in Dart?

I've got a Dart application that consists of both client and server components. There are a couple of source files that are needed by both client and server. I'm trying to find a way to share them effectively without publishing a library to pub.
I've read through these docs but it doesn't say how to share a library if you don't want to publish it to pub. I'd like to do something like:
import 'package:../../Shared/lib/shared.dart';
But that doesn't work ("Target of URI does not exist").
What options do I have here?
Ah, I figured it out. I have to declare a dependency in my pubspec.yaml like this:
shared:
path: ../shared
Then I can just do this:
import 'package:shared/shared.dart';

Hyperledger Composer: Where is the Open API Specification generated by composer-rest-server stored?

I want to use the specification in to generate a Java client using swagger codegen in order to consume the REST API from a Java application. Where do I find the Open API spec after I start the composer-rest-server? I've tried looking it up but I can't figure out where that file is stored after it is generated.
By default, the docs are at your localhost:3000/explorer
This is generated automatically by the LoopBack framework.
You should carefully follow: https://hyperledger.github.io/composer/integrating/getting-started-rest-api.html

Usage of HTTPRequest APIs for Server side app

Below chunk of code seems to require dart:io.
HttpRequest.getString(uri).then(onDataLoaded);
The App that is being designed requires to make HttpRequests to fetch metadata and build up a HTML page. But when the below is executed, an error related to dart:io of not being availble in Dartium is output on console.
Error as below
The built-in library 'dart:io' is not available on Dartium.
Any suggestions would be helpful.
You haven't provided much code to see what you are actually doing.
In the browser you need to import import 'dart:html'; and use the HttpRequest class from there.

How to run DartVoid Vane application on localhost

In Vane Roadmap:
Better support for running Vane on localhost. Right now it's certainly
possible to run Vane on localhost, but it's a little bit tricky. On
DartVoid we autogenerate a dart based server using the http_server
package. And all you need to initialize a Vane class is a standard
HttpRequest object. So, this will come soon hopefully. You can find
your autogenerated server.dart file at the root of you app if you have
a DartVoid app (it's not generated if you use a different framework).
I've created Guestbook sample application and file server.dart was missing.
Is Guestbook sample DartVoid app?
Can I reach generated server.dart file via GitHub?
Is there another way to reach this file?
Please create tags for Vane and DartVoid...
File can be reached from application:
import 'dart:async';
import 'dart:io';
import 'package:vane/vane.dart';
String collectionName = "posts";
class GetAllPosts extends Vane {
Future main() {
log.info("Guestbook : GetAllPosts");
new File("server.dart").readAsString().then((String fileContent){
log.info(fileContent);
});
return end;
}
}
Content of file will appear in system console in http://manage.dartvoid.com
TL;DR
Vane doesn't need an auto-generated server.dart file anymore, which makes it super easy to use.
Long answer
As the co-founder of DartVoid and a co-author of Vane maybe I can give a small update on how we have improved Vane's routing.
We have since the OP's question moved away from auto-generating a server file and instead we use annotations to declare Routes. At startup we parse these routes to build the 'routing table'.
If you're interested in knowing the gritty details and see a couple of examples, I recommend that you head over to the project repository at:
https://github.com/DartVoid/Vane

The built-in library 'dart:io' is not available on Dartium

I don't know where is the problem. This error show up when I import my SystemCheck class to main Dart file.
SystemCheck class:
import 'dart:io';
class SystemCheck{
getOperatingSystem() => Platform.operatingSystem;
getUser() => Platform.localHostname;
}
Import in main file:
import 'cz.felguide.core/system.dart';
That's correct. You cannot use dart:io in Dartium or code designed for running in the browser. For this simple example much of what you want can be found in the Navigator class such as Navigator.platform
Dart has the same limitations as Javascript in that code that is running in a browser cannot natively access the File System of the running client. There are some exceptions such as the specialized Chrome Packaged Apps which allow certain permissions just within Chrome. Even then they require the app to specifically request the extra permissions and the user to grant them.

Resources