Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

mdvorak/resource-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

555aeed · Feb 14, 2018
Nov 17, 2017
Feb 14, 2018
Dec 29, 2017
Mar 16, 2017
Dec 31, 2017
Mar 21, 2017
Feb 12, 2018
Feb 14, 2018
Feb 13, 2018
Feb 14, 2018
Feb 12, 2018
Feb 11, 2018
Feb 13, 2018
Nov 17, 2017
Feb 6, 2018
Dec 29, 2017
Nov 17, 2017

Repository files navigation

resource-router

Build Status

Angular routing engine that drive views by media types. It loads data itself, and by response Content-Type header it displays configured view. It is a replacement for original Angular Router (they cannot be used at the same time).

The aim of this library is to allow building of RESTful clients using Angular, following HATEOAS principle.

See CHANGELOG for release changes.

Installation

npm i angular-resource-router --save

Configuration

Sample snippet how is the router configured. It is very similar to original router, but instead of registering paths, we are registering media types.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ResourceRouterModule } from 'angular-resource-router';
import { AppComponent } from './app.component';
import { SampleComponent } from './sample.component';
import { ErrorComponent } from './error.component';

@NgModule({
  declarations: [
    AppComponent,
    SampleComponent
  ],
  imports: [
    BrowserModule,
    ResourceRouterModule.configure({
      prefix: 'api/'
    }),
    ResourceRouterModule.forTypes([
      {
        type: 'application/x.sample',
        component: SampleComponent
      },
      {
        status: '*',
        type: '*',
        component: ErrorComponent
      }
    ])
  ],
  bootstrap: [
    AppComponent
  ]
})
export class ExampleModule {
}

How It Works

TODO

Development

Before development, run

npm run bootstrap

it will create necessary symlinks for build to pass.

Note: Under linux, you need to change global npm prefix to user accessible directory, see How to Prevent Permissions Errors.

Library

Build of the library is performed with

npm run build

Publishing

To publish new library version to npm repository:

  1. Verify/set library version in src/lib/package.json
  2. Make sure there are release notes in the CHANGELOG.
  3. Commit and push changes, if any
  4. Create a new release on GitHub, in the format v0.0.0 (or alternatively use git directly)
  5. Copy changelog markdown text to the release
  6. Build the library and make sure all tests passed
    npm run bootstrap
    npm run build
    
  7. Publish the library
    npm publish dist/angular-resource-router
    
  8. Merge the branches if needed

Demo app

Local development server can be started with

npm start

TODO

Things that are yet to be implemented

  • Complete README
  • Complete example
  • Support for resolve and data route configs
  • Support for outlet layouts, outlet resolve
  • Outlet context data (name etc)
  • Navigation within outlet
  • Hide element if empty link
  • External navigation for unknown type
  • Build and publish docs
  • Typedoc