Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

NodeJS how to export REST API endpoint/models definition to a typescript module for use on the client? [closed]

$
0
0

In order to have the least boilerplate code possible between my Client - Server stack i would like to define my REST Api & Model layer just once.

So ideally i would like to have on the server side for example an endpoint that gets the user:

Server

Model

interface User {  id: number;  name: string;}

Endpoint (returns User)

/User/id {GET}

Client

On my ReactNative or React client i would like to be able to re-use the code from the server side in a simple manner like bellow:

import { MyRestAPI , User } from "../Server/API"; //(In case of mono repo shared code approach)function GetUserDetails() : User{    let user = await MyRestAPI.GetUser(currentUserId);}

Is there a simple way ?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>