
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Reduce boilerplate when creating crud endpoints Hooks are just middlewares that run before each of the handlers.
/pages/api/posts/[[...id]].ts
import getConfig from 'next/config'
import * as mongoose from 'mongoose'
import { createService, hook, NotFoundError } from 'api-next'
export interface PostAttrs {
title: string
}
export interface PostDoc extends mongoose.Document {
title: string
likes: number
}
interface PostModel extends mongoose.Model<PostDoc> {
build(attrs: PostAttrs): PostDoc
}
const postSchema = new mongoose.Schema({
title: {
type: String,
require: true,
},
likes: {
type: Number,
require: false,
default: 0,
},
})
const name = 'Post'
const Post = (mongoose.models[name] ||
mongoose.model<PostDoc, PostModel>(name, postSchema)) as PostModel
// From express-validator
const validateBody = hook.validateRequest(({ body, query, cookies }) => [
body('title').isString().notEmpty().withMessage('Title is required'),
])
const config = getConfig()
// Concept from Feathersjs: https://feathersjs.com/
const hooks = {
before: {
all: [
hook.connectToDatabase({
name: 'posts-db',
connect: () =>
mongoose.connect(config.serverRuntimeConfig.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
}),
}),
],
create: [validateBody],
update: [validateBody],
},
}
// All the keys are optional
// Pick what you need
export default createService({
hooks,
find: async () => Post.find(),
create: async (body: PostAttrs) => Post.build(body),
get: async (pk) => Post.findById(pk),
update: async (pk, body: PostAttrs) => {
const post = await Post.findById(pk)
if (!post) throw new NotFoundError()
post.set(body)
await post.save()
return post
},
remove: async (pk) => {
const post = await Post.findById(pk)
if (!post) throw new NotFoundError()
await post.remove()
return { success: true, data: post }
},
})
import { createMongooseService } from 'api-next'
const { find, create, get, update, remove } = createMongooseService(Post)
export default createService({
hooks,
find,
create,
get,
update,
remove,
})
FAQs
## Usage (example with mongoose)
The npm package api-next receives a total of 4 weekly downloads. As such, api-next popularity was classified as not popular.
We found that api-next 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
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.