
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
quiz-api-client
Advanced tools
Quiz API Client is a JavaScript Library with support in the browser and Node.js. We follow a standard RESTful model mirroring [restful.js](https://github.com/marmelab/restful.js) as well as including some of the quiz API's specific use cases.
Quiz API Client is a JavaScript Library with support in the browser and Node.js. We follow a standard RESTful model mirroring restful.js as well as including some of the quiz API's specific use cases.
The Quiz API client is initialized just like any class requiring only two arguments:
endpoint: The base endpoint of the API. You can supply config specific endpoints based on what
environment you are end. (e.g. http://question.docker/api)loadToken: A function that makes a request to your service to obtain a token. It is, currently,
the responsibility of the consumer to determine which token is necessary for the call to succeed.
This function call should return a promise with the token on success and an error on failure. The
client will call it again should the first call fail, but will throw an error after that. The
client will cache the token and recall in the event that it fails authorization.Example
function loadToken() {
return fetch('http://myservice.com/API/TO/TOKEN')
.then(result => result.json())
.then(({ token }) => token)
.catch((err) => { throw err; });
}
const client = new QuizApiClient(
'http://question.docker/api',
loadToken
);
// client available to make requests
The quiz API client provides an interface to follow most of the standard REST queries. The first parameter is always the name of the resource as a string. The last parameter is always an optional object to represent options to pass along. Each request returns a promise that will provide an instance (or array of instances) of the resource specified.
Performs a GET request with an id for the resource; it resolves to an instance of the resource.
Parameters:
Example:
client.get('ResourceName', 4, { additional: 'options' })
Performs a GET request with no id and resolves all resources of that type.
Parameters:
Example:
client.getAll('ResourceName', { additional: 'options' })
Most Quiz API responses are limited to a page size of 50. To paginate through
the results, call paginate:
const paginator = client.paginate('ResourceName', { additional: 'options' })
paginator.getPage(1) // fetches the records from the first page
paginator.totalPages // fetch at least one page before checking the total
To exhaustively fetch all records, page by page:
paginator.getAll()
Performs a POST request with no id and resolves to the new resource (with an identifier).
Parameters:
Example:
client.create('ResourceName', { title: 'Winnie the Pooh' }, { additional: 'options' })
Performs a PUT request to update a specific resource and resolves to the updated resource.
Parameters:
data will have a field, id.Example:
client.update('ResourceName', 4, { title: 'Winnie the Pooh' }, { additional: 'options' })
// or
client.update('ResourceName', { id: 4, title: 'Winnie the Pooh' }, { additional: 'options' })
Performs a PATCH request to patch a specific resource and resolves to the patched resource.
Parameters:
data will have a field, id.Example:
client.patch('ResourceName', 4, { title: 'Winnie the Pooh' }, { additional: 'options' })
// or
client.patch('ResourceName', { id: 4, title: 'Winnie the Pooh' }, { additional: 'options' })
The quiz API deviates from REST in a few cases, specifically when we wish to perform an action on a
specific resource. We can do that with the performAction method.
Parameters:
In a quiz session, you can update the user's response, which makes a request through the kinesis stream.
client.performAction('QuizSession', { id: 4, ...}, 'userResponse', { sessionItem: {...}, userResponse: {...} })
Interested in adding resources/actions? Take a look at the records folder in this package. Every
resource extends BaseRecord, and resources that connect to the server extend ApiRecord.
To create a new resource that connects to the server, extend ApiRecord. At its basic level, you
will most likely need to update the following methods.
static schema() - returns a joi-browser
object to build a schema to validate/sanitize datastatic resourceName() - returns a string for the name of the resource to be used in URLs. More
advanced URL schemes will override `basePath()static methodsSupported() - returns an array of strings representing all methods supported. None
are supported by default.const Joi = require('joi-browser')
const ApiRecord = require('../ApiRecord')
class QuizEntry extends ApiRecord {
static schema() {
return Joi.object().keys({
entryEditable: Joi.boolean(),
entryType: Joi.string().valid('Item', 'BankEntry', 'Bank', 'Stimulus'),
id: Joi.string().required(),
pointsPossible: Joi.number(),
position: Joi.number().integer(),
properties: Joi.object(),
regradeAdjustedPointsPossible: Joi.number(),
regradeAdjustedScoringData: Joi.object(),
status: Joi.string().valid('mutable', 'immutable'),
stimulusQuizEntryId: Joi.string(),
cloneOfId: Joi.string()
})
}
static methodsSupported() {
return ['getAll', 'get', 'create', 'update', 'delete']
}
static resourceName() {
return 'quiz_entries'
}
basePath({ quizId }) {
return `/quizzes/${quizId}/${this.constructor.resourceName()}`
}
getActions() {
return {
clone: (fetcher, options) =>
fetcher.post({ url: `${this.basePath(options)}/${this.data.id}/clone` })
}
}
}
module.exports = QuizEntry
Each resource has a getActions() method that returns an object mapping the name of the action to a
function. The function has the following parameters:
util/Fetcher
directory for more information.While the function can return anything, we strongly recommend returning a promise.
In the following example, a quiz session has two actions: take and submit.
class QuizSession extends ApiRecord {
// ...
getActions() {
return {
take: fetcher =>
fetcher
.post({ url: `${this.basePath()}/${this.data.id}/take` })
.then(body => new this.constructor(this.transformResponse(body)))
.catch(err => {
throw err
}),
submit: (fetcher, { sessionItemResponses }) =>
fetcher
.post({
url: `${this.basePath()}/${this.data.id}/submit`,
body: {
session_item_responses: sessionItemResponses
},
noDecamelize: true
})
.then(body => new this.constructor(this.transformResponse(body)))
.catch(err => {
throw err
})
}
}
}
The following is planned for future development.
FAQs
Quiz API Client is a JavaScript Library with support in the browser and Node.js. We follow a standard RESTful model mirroring [restful.js](https://github.com/marmelab/restful.js) as well as including some of the quiz API's specific use cases.
The npm package quiz-api-client receives a total of 51 weekly downloads. As such, quiz-api-client popularity was classified as not popular.
We found that quiz-api-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.