Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

datapages-actions

БесплатноБез исполняемых скриптовНе проверен

Write Datapages action handlers (GET, POST, PUT, PATCH, DELETE, QUERY): file responses, parameters, return values, Datastar signals, SSE patching, HTTP error…

romsharkот romshark★ 122 звезды на GitHub

Об этом скилле

Actions

Read datapages first for the build loop, hard rules and naming conventions.

Define a page action as a value-receiver method on its page type. Define an action not tied to a page as a method on *App. Give each action 1 route doc comment. A page action route must be below its page route. For example, /login/submit is valid for PageLogin at /login. An action route cannot end in a {name...} wildcard. Pass that value in a query parameter or a signal.

// POSTSubmit is /login/submit
func (PageLogin) POSTSubmit(r *http.Request) error { return nil }

// POSTSignOut is /sign-out/{$}
func (*App) POSTSignOut(r *http.Request) error { return nil }

GETXXX is a file action, not the page's GET handler. A browser loads it by URL from a link, image or download. It must return datapages.File and may take only *http.Request, Session, Path and Query. The generated href package builds its URL. A GET action skips CSRF checks and must not change server state.

Use a QUERYXXX action for a read that sends data in the body, such as a search with a large filter. It skips the CSRF check because QUERY is a safe method. Never change state in it.

Parameters

Parameters may appear in any order because the generator matches them by type. Names are unrestricted except for stateID. Read wrapped values from .Values.

type what
*http.Request required
datapages.SSE patches the stream of the calling page; page actions only, not *App actions
Session the current session, see datapages-sessions
datapages.Path[struct{...}] route variables, path:"id" tags
datapages.Query[struct{...}] query parameters, query:"p" tags
datapages.Signals[struct{...}] signals sent by the client, json:"v" tags
datapages.State[StateX] per-tab server state, see datapages-state
stateID string tab event address; requires State[T], see datapages-state
datapages.PageCacheWriter writes the offline page cache, see datapages-offline
datapages.Dispatcher[EventX] publishes EventX, see datapages-events

The name in a Signals field's json tag must match [A-Za-z_][A-Za-z0-9_]* and must not contain __. json:"-" is invalid. Omit a field to exclude it. Nested structs define signal paths.

Return values

A non-GET action may return only error. Other supported return types are datapages.Component, datapages.Head, datapages.DocumentAttrs, datapages.Redirect, datapages.NewSession[Data], datapages.CloseSession and datapages.File. Return values may appear in any order. datapages.Head and datapages.DocumentAttrs require datapages.Component. Datastar morphs a returned body into the open document, including the attributes of <html>, so return the same datapages.DocumentAttrs as the page's GET.

) (redirect datapages.Redirect, err error) {
	return datapages.Redirect{URL: href.PageIndex()}, nil
}

Redirect.Status defaults to 302. Datastar requests ignore it because they cannot follow an HTTP redirect. They navigate by assigning window.location.

Do not combine datapages.SSE with session changes. An sse parameter causes the response headers to be sent before the handler runs, so the handler cannot set or delete the session cookie. The generator rejects newSession or closeSession with sse. A redirect still works because it uses the stream. A returned datapages.Component is rejected with sse too: send it with sse.PatchElement instead.

An action's SSE response uses datapages.WithSSECompression, not the page's StreamConfig. Configure it with a method named StreamConfig plus the action's method name, such as StreamConfigPOSTSave, on the same page or App; see datapages-events.

Files

A named GET action serves a file at its route:

// GETImage is /images/{name}
func (a *App) GETImage(
	r *http.Request,
	path datapages.Path[struct {
		Name string `path:"name"`
	}],
) (datapages.File, error) {
	// a.images opens through an os.Root: the name is unescaped
	// and can hold "/" and "..".
	f, contentType, err := a.images.Open(path.Values.Name)
	switch {
	case errors.Is(err, fs.ErrNotExist):
		return datapages.File{}, datapages.ErrNotFound
	case err != nil:
		return datapages.File{}, err
	}
	return datapages.File{Type: contentType, Body: f}, nil
}

A path value holds its segment unescaped: %2F arrives as / and %2E%2E as ... Open a file through an fs.FS or an os.Root, or look the value up as a key. Never join it into a file path.

Any action may return datapages.File. The file is the complete response, so it may be accompanied only by error, which is optional. A file action cannot take datapages.SSE or datapages.PageCacheWriter.

Body is an io.ReadSeekCloser, which Datapages closes after serving. Content held in memory needs a Close that does nothing: a bytes.Reader has none, and io.NopCloser drops Seek.

Полный SKILL.md на GitHub

Установить datapages-actions в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл datapages-actions?

Write Datapages action handlers (GET, POST, PUT, PATCH, DELETE, QUERY): file responses, parameters, return values, Datastar signals, SSE patching, HTTP error status codes and the RecoverError hook.

Как установить скилл datapages-actions?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл datapages-actions запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить datapages-actions с