
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@fresh-data/framework
Advanced tools
Fresh Data Framework is a declarative data API framework for JavaScript apps.
Fresh Data is new. Very new. As such it should not be used in production just yet! This code will be changing still.
Try it out on something noncritical and provide some feedback!
npm install --save @fresh-data/framework
There is support for React applications using Redux for an internal cache available from @fresh-data/react-redux
Each API Specification can be kept in your application or a separate module.
import { compact, startsWith } from 'lodash';
const URL_ROOT = 'http://example.com/';
const get( endpointPath, params ) => {
const uri = URL_ROOT + endpointPath.join( '/' );
const queryString = qs.stringify( params );
return fetch( `${ uri }?${ query }` );
}
const put( endpointPath, params ) => {
const uri = URL_ROOT + endpointPath.join( '/' );
const { data } = params;
return fetch( uri, { method: 'PUT', body: JSON.stringify( data ) } );
}
const apiSpec = {
operations: {
read: ( resourceNames ) => {
return compact( resourceNames.map( resourceName => {
if ( startsWith( resourceName, 'thing:' ) ) {
const thingNumber = resourceName.substr( resourceName.indexOf( ':' ) + 1 );
const request = get( [ 'things' ] ).then( responseData => {
return { [ resourceName ]: { data: responseData } };
} );
return request;
}
} ) );
},
update: ( resourceNames, resourceData ) => {
return compact( resourceNames.map( resourceName => {
if ( startsWith( resourceName, 'thing:' ) ) {
const thingNumber = resourceName.substr( resourceName.indexOf( ':' ) + 1 );
const data = resourceData[ resourceName ];
const request = put( [ 'things' ], { data } ).then( responseData => {
return { [ resourceName ]: { data: responseData } };
} );
return request;
}
} ) );
}
},
mutations: {
updateThing: ( operations ) => ( thingId, data ) => {
const resourceName = `thing:${ thingId }`;
const resourceNames = [ resourceName ];
const resourceData = { [ resourceName ]: data };
return operations.update( resourceNames, resourceData );
}
},
selectors: {
getThing: ( getResource, requireResource ) => ( requirement, thingId ) => {
const resourceName = `thing:${ thingId }`;
return requireResource( requirement, resourceName );
}
}
};
export apiSpec;
Your own API depends on the operations, methods, and selectors you define.
Fresh Data is functional, but still a work in progress. Here's what's next on the list:
FAQs
Describe the data you need and simply use it in your app.
We found that @fresh-data/framework 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.