
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
The best way to build large Redux applications over RESTful APIs. Easy to use with all popular Redux side-effect libraries.
Use either of these commands, depending on the package manager you prefer:
yarn add apium
npm i apium
Add the middleware and the reducer to a Redux store.
import { createStore, applyMiddleware, combineReducers } from "redux"
import { apiumReducer, makeApiumMiddleware } from "apium"
const store = createStore(
combineReducers({ apium: apiumReducer }),
applyMiddleware(makeApiumMiddleware()),
)
Trigger a request in your React component by dispatching a custom command action.
const UserList = () => {
const users = useSelector(getUsers)
const dispatch = useDispatch()
useEffect(() => {
dispatch(fetchUsers())
}, [])
return <List items={users} />
}
Perform a request based on the custom action.
import { request } from "apium"
// With `redux-saga`.
function* fetchUsersSaga(action) {
const { payload } = yield putResolve(request({ url: "/users" }, { origin: action }))
yield put(storeUsers(payload))
}
function* watchFetchUsers() {
yield takeEvery(ActionTypes.fetchUsers, fetchUsersSaga)
}
// With `redux-observable`.
const fetchUsersEpic = action$ =>
action$.pipe(
ofType(ActionTypes.fetchUsers),
mergeMap(action => request({ url: "/users" }, { origin: action })),
map(({ payload }) => storeUsers(payload)),
)
// With `redux-thunk`.
const fetchUsers = () => async dispatch => {
const { payload } = await dispatch(request({ url: "/users" }, { origin: action }))
dispatch(storeUsers(payload))
}
// Without any additional libraries.
const fetchUsersMiddleware = ({ dispatch }) => next => async action => {
next(action)
if (action.type === ActionTypes.fetchUsers) {
const { payload } = await dispatch(request({ url: "/users" }, { origin: action }))
dispatch(storeUsers(payload))
}
}
Use the isFetching
selector factory.
import { isFetching } from "apium"
const isFetchingUsers = isFetching(ActionTypes.fetchUsers)
const UserManagement = () => {
const fetchingUsers = useSelector(isFetchingUsers)
if (fetchingUsers) {
return <Spinner />
}
return <UserList />
}
You should probably read this entire section before using the library.
Suppose we want to fetch all users from a RESTful API.
"FETCH_USERS"
."FETCH_USERS"
command actions."FETCH_USERS"
action as action.meta.origin
.isApiumSuccess("FETCH_USERS")
predicate or use the await
syntax.This flow is slightly simplified when using Redux Thunk, which is not reliant on listening to certain types of actions.
When an Apium request is dispatched, the Apium middleware does not use the action as its return value directly. Instead, it adds a .then
property to the action, making it a thenable. Thenables behave similarly to promises in that they are supported by the await
syntax.
It is necessary to pass the action.meta.origin
property to all Apium requests. This is what makes it possible to use the isFetching
selector factories. You must always use a custom command action as the origin, i.e. you cannot use Apium actions directly. This is to encourage good coding practices:
request()
directly in your components. Instead, you should always dispatch custom actions, such as fetchUsers()
, for better decoupling and readability.isFetching
selector factory usable without any further changes to existing code.Should you need to automatically attach a JWT as the Authorization: Bearer <jwt>
HTTP header, you have several options on how to achieve this:
configure({ baseHeaders: { Authorization: "Bearer <jwt>" } })
action.makeApiumMiddleware({ transformRequestAction })
. This allows you to retrieve the JWT from Redux state and modify all request actions to have the JWT included in the header.See the CHANGELOG.md file.
All packages are distributed under the MIT license. See the license here.
FAQs
Redux middleware for event-driven HTTP requests with async/await support.
The npm package apium receives a total of 56 weekly downloads. As such, apium popularity was classified as not popular.
We found that apium demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.