Mocking Service Beta Released


#1

Tonight we released into beta an exciting new tool for the RAML ecosystem - the RAML Mocking Service.

Integrated with the API Designer, you can now mock a RAML spec with a single button click and no configuration. Your mocked API will immediately be live, persists indefinitely, updates as you save changes to your RAML spec, and can be exercised with the API Console, API Notebook, or with your own client code. It can be accessed via the mock baseURL that is automatically injected into your RAML spec on activation. Let us know what you think, and post bugs in this forum in you find them!

A more in depth post on the capabilities of the mocking service is coming soon, but for now you can check it out on your own, using any valid RAML spec.

####Mocking Service Features####

  • Request parameter validation (type-match, required)
  • Request body validation base on schemas
  • Mocked responses using example data
  • API Mocks update as you save your work

####Mocking Service Usage####
To activate the mocking service for a RAML spec, simply click the new “Mocking Service” button in the top right of the API Designer toolbar. The mocking service is now on, and will update whenever you save your RAML spec. You can immediately starting using the API Console to play around with your API.


#2

This topic is now pinned. It will appear at the top of its category until it is either unpinned by a moderator, or the Clear Pin button is pressed.


#3

Hi, first off, thanks for this, it looks great.
Question: Is the mock service code currently in github or are there any plans to release it?

Thanks.


#4

The mocking service code is not currently open sourced. I don’t have a hard answer on future plans, other than being able to say regardless of the source code availability, we plan to continue operating it as a free, widely-accessible, hosted mocking service.

Once we come to a decision on the end-state of the source code licensing, I’ll let you know.

//Dillon


#5

Seems the mocking service doesn’t support CORS. Are there any plans to send Access-Control-Allow-Origin header on mock service replies?


#6

Also/Alternatively are there any plans to support JSONP?


#7

I know this is in beta but I wish this was working and open sourced. I have to pass up on using the API Designer because there is no working Mocking Service. :dizzy_face:

Currently trying to click the button results in:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/proxy/http://mocksvc.mulesoft.com/mocks

when I run the API Designer locally.

Any workarounds?


#8

Hi @jewelsjacobs,

That’s actually a tricky bit with the API Designer, not the mocking service. It’s trying to hit a proxy (which doesn’t exist on your local version obviously) to handle CORS support. You can disable the proxy (persistently) as detailed:

If you need CORS support, which you may need to successfully use the mocking service, you can alternatively provide your own proxy. To configure this, follow the instructions of the example above, but provide the url of the proxy you wish to use instead of “false” as the value for RAML.Settings.proxy =

We’ll be adding UI to help smooth this whole experience out in a release this summer.

Hope that helps!

//Dillon


#9

Hi @jewelsjacobs ,

I had almost the same problem, however, there is one particular difference, I’m wondering if you updated the API Designer default port; I access the API-D by using the port number 9013, as far as I know, raml-store uses the port number 3000 by default to publish its service to allow API-D to store the RAML files into a MongoDB.

You might double check it just to be sure.

BR


#11

I temporarily hacked up an app to get the raml-store and api designer to work:
raml-store-with-api-designer (https://github.com/jewelsjacobs/raml-store-with-api-designer)

This is the app I’m running which gives me the Mock Service error.

It’s basically a combo of the current raml-store project and the RAML API Designer files from the dist folder served on one instance of express.

express is serving the API designer and raml-store service on the same port. 3000 by default, although you can change this with a PORT environment variable value.

So I don’t think its a port issue although who knows. I’ll try changing the app port to 9013. If that doesn’t work I’ll try disabling the proxy.

Thanks!


#12

Changing the port doesn’t do it:

POST http://10.14.213.164:9013/proxy/http://mocksvc.mulesoft.com/mocks 404 (Not Found)

I’m going to try disabling the proxy . . .


#13

Well disabeling the proxy gives me:

XMLHttpRequest cannot load http://mocksvc.mulesoft.com/mocks. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.14.213.164:9013' is therefore not allowed access. 

I’ll keep at it.


#14

Hi @jewelsjacobs

Sorry for the confusing response before, was short on time. Here are some more details for you.

That error message is expected with the proxy disabled, since the designer/console is a client-side application. We don’t enable CORS by default on the mocking service because it is an implementation decision at the API level, and we endeavor to respect your API definition when mocking it.

To make it work, you have two options. You will need to either supply your own proxy that can be reached by the local copy of API Designer, or put CORS headers into your RAML file as part of your response definitions for methods you’d like accessible via CORS.

CORS support can be added to any API by returning the Access-Control-Allow-Origin header, with either a wildcard value or a specific domain you want to provide CORS access for. In the example below, the Access-Control-Allow-Origin header will be mocked and return the example value provided for any 200 response for a POST to /example, which allows that resource and method to be accessed via CORS. You can simplify this and avoid repetition across multiple methods by leveraging Traits and ResourceTypes to establish a responses pattern and re-use it.

#%RAML 0.8
title: "CORS Example"
/example:
  post:
    responses:
      200:
        headers:
          Access-Control-Allow-Origin:
            example: |
              *

I just tested mocking the above with the API Designer and a disabled proxy, and it worked as expected, so I hope this helps unblock you!

//Dillon

edit: @Eric_Price This should answer your previously un-answered question on CORS support! Sorry I missed that one initially.


#15

Would you mind posting the RAML spec of the mocking service itself?


#16

Still doesn’t work :frowning:


#17

Any update on this?


#18

Hi @jewelsjacobs,

Sorry for the silence - I’ve been pretty heads down with conference stuff (my company was putting a few on) for the past week and a half, and haven’t spent as much time on these forums as I’d like.

I haven’t been able to reproduce this - if you DM me an email or skype handle, we can do a google hangout/skype and screenshare so I can try to help you troubleshoot, or at least identify how to reproduce this behavior on my end so I can try to resolve it.

Thanks!


#19

Thanks @comptly !

I’ve been corresponding with Norberto and have just been too swamped with my day job to work on this right now.

I’ll get with you when some time frees up.

Thanks!


#20

Hey,

I need mocking services but with limited LAN connection only,
Is there any alternative approach for mocking easily with a local version?

Thanks


#21

Hey @asaf000,

as far as I now - unfortunately not with the API Designer embedded mocking service. What you could do is creating a mock by yourself using osprey.

Hope that helps.

Cheers,
Christian