https://github.com/nmartinezb3/react-native-http-server
A simple HTTP server for react native
https://github.com/nmartinezb3/react-native-http-server
ios javascript react react-native swift
Last synced: 6 days ago
JSON representation
A simple HTTP server for react native
- Host: GitHub
- URL: https://github.com/nmartinezb3/react-native-http-server
- Owner: nmartinezb3
- Created: 2020-04-28T22:40:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:51:49.000Z (over 3 years ago)
- Last Synced: 2025-10-07T10:54:25.367Z (10 months ago)
- Topics: ios, javascript, react, react-native, swift
- Language: Swift
- Homepage:
- Size: 1.75 MB
- Stars: 12
- Watchers: 1
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-native-http-server
An HTTP server for react native based on https://github.com/swisspol/GCDWebServer
## Getting started
`$ npm install http-server-react-native --save`
### Mostly automatic installation
`$ react-native link http-server-react-native`
### Manual installation
#### iOS
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
2. Go to `node_modules` ➜ `react-native-http-server` and add `RNHttpServer.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libRNHttpServer.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. Run your project (`Cmd+R`)<
#### Android
Not supported yet
## Usage
```javascript
import React, { Component } from 'react';
import { HttpServer, Router } from 'http-server-react-native';
class Server extends Component {
componentDidMount() {
const router = new Router('/path');
router
.get(data => {
return { status: 200, data: { some: 'data' } };
})
.post(data => {
return { status: 200, data: { some: 'data'} };
})
.put(data => {
return { status: 200, data: { some: 'data'} };
})
.patch(data => {
return { status: 200, data: { some: 'data'} };
})
.delete(data => {
return { status: 200, data: { some: 'data'} };
})
this.server = new HTTPServer({ port: 8080 });
this.server.registerRouter(router);
this.server
.start()
.then(url => console.log(`Server running on ${url}`)
.catch(err => console.error(err));
}
componentWillUnmount() {
this.server.stop()
}
...
}
;
```