React-Native using Expo - Buffer variable

I’m using the servicestack-client in a React-Native projected created in the latest Expo XDE.

Every is fine until I attempt to make a call

 const req = new dto.GetCompanies();
  client.get(req).then((response) => console.log('response', response));

I get the following error message

Possible Unhandled Promise Rejection (id: 0):
ReferenceError: Can’t find variable: Buffer

Is it possible to use typed request or the serviceclient in Expo?

It wan’t tested with it, but I’ve just tried it and it’s working for me. But the platform may not support downloading raw data like byte[] in case that’s what you’re trying to do.

Steps used in test Expo App:

  1. Download Windows expo IDE from https://expo.io
  2. Install servicestack-client

npm install servicestack-client

If you don’t have servicestack-cli installed, you can install it with:

npm install -g servicestack-cli

Download TechStacks DTOs

ts-ref http://techstacks.io

Compile TypeScript DTOs to JavaScript since Expo is only configured to use JavaScript:

tsc techstacks.dtos.ts

Modify App.js to include TestApp that calls TechStacks FindTechStacks API:

import React from 'react';
import { StyleSheet, Text, View, TextInput, Button } from 'react-native';

import { JsonServiceClient } from 'servicestack-client';
import { FindTechStacks } from './techstacks.dtos';

const client = new JsonServiceClient("http://techstacks.io");

export default class App extends React.Component {
  state = {
    inputValue: "ServiceStack",
    results: []
  };

  _handleTextChange = inputValue => {
    this.setState({ inputValue });
  };

  _handleButtonPress = () => {
    client.get(new FindTechStacks(), { VendorName: this.state.inputValue })
      .then(r => {
        this.setState({ results: r.Results });
      })
  };

  render() {
    return (
      <View style={styles.container}>
        <Text>Open up App.js to start working on your app!</Text>
        <TextInput
          value={this.state.inputValue}
          onChangeText={this._handleTextChange}
          style={{ width: 200, height: 44, padding: 8 }}
        />
        <Button
          title="Go!"
          onPress={this._handleButtonPress}
        />
        <Text>Results:</Text>
        {this.state.results.map(x => <Text key={x.Id}>{x.Name}</Text>)}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Open in Expo iOS App using QR Code, which I was able to hit Go! button to see results from TechStacks API.

Thanks for you help all is working now !:stuck_out_tongue_closed_eyes: I was dreading the fact that I might have to use untyped requests.

The only step I missed was the compiling using tsc. It turns out that Typescript was not installed globally.

Another question is in my dto.ts I have an error referring to a missing IPost

export class Authenticate implements IReturn<AuthenticateResponse>, IPost 

How can I get ts-ref to include this interface?

This issue has been resolved with the latest pre-release that’s now available on MyGet. You need to upgrade your Server packages not servicestack-cli.