![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
____ _ __ _
/ ___| _ __ ___ __ _ _ __| |_ / _| __ _ ___ ___ (_) ___
\___ \| '_ ` _ \ / _` | '__| __| |_ / _` |/ __/ _ \ | |/ _ \
___) | | | | | | (_| | | | |_| _| (_| | (_| __/ _ | | (_) |
|____/|_| |_| |_|\__,_|_| \__|_| \__,_|\___\___| (_) |_|\___/
-----------------------------------------------------------------
This library is intended to ease network (rest-http) connections easly. First it is developed for Smartface then it is adopted to work both with node.
npm i nw-smf
If you are within a Smartface workspace first switch to scripts folder. Here is a script that does it all:
(cd ~/workspace/scripts && npm i nw-smf)
Examples are not included within the npm package. It is possible to reach examples from github page: https://github.com/smartface/js-lib-nw/
nw relies on XMLHttpRequest object to be global. In Smartface environment it is global. Following code in node makes it global:
if (!global.XMLHttpRequest)
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
Make sure that xmlhttprequest module is installed
npm i xmlhttprequest
const nw = require("nw"); //access to nw settings object
In order to make a call, first you need to register a service definition.
nw.registerService(serviceDefinitionObject);
Service Definition Object is a simple object. Members of the object are defined below:
String format basically is a pattern in the given string and replacing those parameters within the string with given arguments. More details can be reached from: https://www.npmjs.com/package/form-urlencoded
Place them in a separate JSON files (with json extension) and require them.
Pass the require result into nw.registerService(require("myServiceDefinitionFile.json"));
nw settings object provides following API
String. Works kind a prefix to path. It does not add slashes (/) automatically while concatenating with path to form the URL of the service.
Object. All service definitions are placed here. All services are registered with their names and can be accessed through by its name as property. A service definition with same name overwrites the definition.
Function. Creates nw service object from service definition. Service is given as parameter by name of the registered services. Does not expect a service definition as object.
Object. In key-value format. Adds header values to all requests. Useful to modify after login and logout. Also useful if all sevices content-type and/or accept values are same.
Function. Takes a service definition object as parameter. After small validation it adds it to services as a property.
String. Smartface only! All requests are gone through a socks proxy in provided url value of the proxy server.
Boolean. Smartface only! Ignores SSL errors on services
Function. A pre-processor for defining response of the service falls into category of faulty or success based on the http status of the response. Takes status (number) as argument parameter, returns true|false boolean as result. False mean faulty response. By default this is set all status between 200 & 399 are valid, rest not. Can be replaced with assigning this function with another.
Function|Event. Fired before network operation starts. Useful to block UI during network operation. Can be set by assigning the function. Does not takes any argument or returns.
Function|Event. Fired after network operation starts. Useful to remove UI block after network operation completes. Can be set by assigning the function. Does not takes any argument or returns.
nw service object is the real object that handles all network operations. As a pattern every function returns itself (chaining), except chain method. Header value content-type is important before making a request if request has a body. Every request is prepared by its content-type. Every response is also parsed by its response header content-type value and provided as object; if parsing fails then the response body is provided as string.
Function. Sets values in body of the request. In form it can be given as key-value pair, first argument is key, second argument is value; in other scenarios it can be given as single parameter.
Function. Sets the header values for the request in key-value format. First argument is key, second argument is value.
Function. Sets the query string values for the request in key-value format. First argument is key, second argument is value.
Function. Formats the string in path. Each argument is provided as argument to formatter.
Function. Takes a function as an argument. This function is called after network operation for the service completes. This function has two arguments in error-first-pattern err and data. Structure of both argument are same objects. data is null for unsuccessful response or on a network error; err is null on a successful response as defined in nw.requestSuccessValidator.
Objects have following properties:
Creates an another nw service object by the given service definition name (string) in a chained flow. In this case it does not returns the original nw service object instead it returns new nw service object
Function. Runs the services according to the flow. Making an actual call and retrieving values from server.
Function. Does not run the service! Instead executes them in flow after 300ms fires result with the values given in service definition in mock field.
run and mock methods of the nw service object executed in flows.
FAQs
NW libray for Smartface
We found that nw-smf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.